From 78df07c90568e9312c95fe8caf64ed55a5c550d7 Mon Sep 17 00:00:00 2001 From: markus-moser Date: Wed, 22 May 2024 16:18:02 +0200 Subject: [PATCH] Improve search services docs (#156) --- .../06_OpenSearch_Search_Models/README.md | 4 +- doc/04_Searching_For_Data_In_Index/README.md | 41 ++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/doc/04_Searching_For_Data_In_Index/06_OpenSearch_Search_Models/README.md b/doc/04_Searching_For_Data_In_Index/06_OpenSearch_Search_Models/README.md index 9b7b4ed0..eb4269eb 100644 --- a/doc/04_Searching_For_Data_In_Index/06_OpenSearch_Search_Models/README.md +++ b/doc/04_Searching_For_Data_In_Index/06_OpenSearch_Search_Models/README.md @@ -2,7 +2,7 @@ OpenSearch search models can be used when individual OpenSearch queries are needed to streamline the creation of OpenSearch search JSONs. -This is especially useful when you want to create your own [search modifiers](../05_Search_Modifiers/README.md). +This is especially useful when you want to create your own [search modifiers](../05_Search_Modifiers/README.md) or when you would like to create services which should directly execute searches through the OpenSearch client. They are used by the Generic Data Index and its search services internally to handle the execution of search queries on a lower level. ## Example usage in search modifier @@ -178,4 +178,4 @@ $aggregation = new Aggregation('test-aggregation', [ 'field' => 'value', ], ]); -``` \ No newline at end of file +``` diff --git a/doc/04_Searching_For_Data_In_Index/README.md b/doc/04_Searching_For_Data_In_Index/README.md index a372a630..23f9ad15 100644 --- a/doc/04_Searching_For_Data_In_Index/README.md +++ b/doc/04_Searching_For_Data_In_Index/README.md @@ -4,6 +4,7 @@ The Generic Data Index bundle adds standardized and flexible services to search Each search is based on a search service (depending on the element type) and a search model defining the search query. The search models can be created with the [SearchProviderInterface](https://github.com/pimcore/generic-data-index-bundle/blob/1.x/src/Service/Search/SearchService/SearchProviderInterface.php) +The regular way to search for assets, data objects or documents is to use the related search service. ## Asset Search Service @@ -11,13 +12,18 @@ Each search is based on a search service (depending on the element type) and a s - Example: This example loads all assets from the root folder (parent ID 1) and orders them by their full path. ```php -public function searchAction(SearchProviderInterface $searchProvider) +use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface; +use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Asset\AssetSearchServiceInterface; + +public function searchAction(SearchProviderInterface $searchProvider, AssetSearchServiceInterface $asserSearchService) { $assetSearch = $searchProvider->createAssetSearch() ->addModifier(new ParentIdFilter(1)) ->addModifier(new OrderByFullPath()) ->setPageSize(50) ->setPage(1); + + $searchResult = $asserSearchService->search($assetSearch); } ``` @@ -25,7 +31,10 @@ public function searchAction(SearchProviderInterface $searchProvider) - Example: This example loads all data objects from the root folder (parent ID 1) with a specific class definition and orders them by their full path. ```php -public function searchAction(SearchProviderInterface $searchProvider) +use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface; +use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\DataObject\DataObjectSearchServiceInterface; + +public function searchAction(SearchProviderInterface $searchProvider, DataObjectSearchServiceInterface $dataObjectSearchService) { $dataObjectSearch = $searchProvider->createDataObjectSearch() ->addModifier(new ParentIdFilter(1)) @@ -33,16 +42,38 @@ public function searchAction(SearchProviderInterface $searchProvider) ->setClassDefinition($carClassDefinition) ->setPageSize(50) ->setPage(1); + + $searchResult = $dataObjectSearchService->search($dataObjectSearch); +} +``` + + +## Document Search Service + +- Example: This example loads all documents from the root folder (parent ID 1) and orders them by their full path. +```php +use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface; +use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Document\DocumentSearchServiceInterface; + +public function searchAction(SearchProviderInterface $searchProvider, DocumentSearchServiceInterface $documentSearchService) +{ + $documentSearch = $searchProvider->createDocumentSearch() + ->addModifier(new ParentIdFilter(1)) + ->addModifier(new OrderByFullPath()) + ->setPageSize(50) + ->setPage(1); + + $searchResult = $documentSearchService->search($documentSearch); } ``` ## Search Modifiers To influence the data which gets fetched its possible to use so-called search modifiers. -Find out details about search modifiers in the [search modifiers documentation](05_Search_Modifiers/README.md). +Find out details about search modifiers in the [search modifiers documentation](05_Search_Modifiers/README.md). There you will also find information on how to create your own custom search modifiers. ## OpenSearch Search Models -OpenSearch search models can be used when individual OpenSearch queries are needed to streamline the creation of OpenSearch search JSONs. +The search services mentioned above offer a flexible and structured way to search for assets, data objects and documents. Nevertheless if there are requirements which are not covered by the search services it might be needed to develop your own customized open search queries. The OpenSearch search models offer a streamlined way for executing such customized search queries. They are also used by the search services internally to create the executed OpenSearch search queries. Take a look at the dedicated [OpenSearch search models documentation](06_OpenSearch_Search_Models/README.md) to find out more. @@ -60,4 +91,4 @@ To debug the OpenSearch queries which are created by the search service, it is p | Get Parameter | Description | |---------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `debug-open-search-queries` | Will change the response of the called URL and outputs all executed OpenSearch queries.

It is possible to influence the output verbosity with the value of the parameter (1=normal, 2=verbose, 3=very verbose) | \ No newline at end of file +| `debug-open-search-queries` | Will change the response of the called URL and outputs all executed OpenSearch queries.

It is possible to influence the output verbosity with the value of the parameter (1=normal, 2=verbose, 3=very verbose) |