Skip to content

Commit

Permalink
Improve search services docs (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-moser authored May 22, 2024
1 parent 892148e commit 78df07c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -178,4 +178,4 @@ $aggregation = new Aggregation('test-aggregation', [
'field' => 'value',
],
]);
```
```
41 changes: 36 additions & 5 deletions doc/04_Searching_For_Data_In_Index/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,76 @@ 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

### Example usage

- 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);
}
```

## Data Object Search Service

- 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))
->addModifier(new OrderByFullPath())
->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.

Expand All @@ -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. <br/><br/>It is possible to influence the output verbosity with the value of the parameter (1=normal, 2=verbose, 3=very verbose) |
| `debug-open-search-queries` | Will change the response of the called URL and outputs all executed OpenSearch queries. <br/><br/>It is possible to influence the output verbosity with the value of the parameter (1=normal, 2=verbose, 3=very verbose) |

0 comments on commit 78df07c

Please sign in to comment.