From dd35eea56b5a1377e524152ee7c4697a3cc50432 Mon Sep 17 00:00:00 2001 From: Alexander Schiwjow Date: Mon, 6 Jan 2025 15:01:29 +0100 Subject: [PATCH] Example for Pimcore Documents (#51) --- docs/0_ExampleSetup.md | 108 ++++++++++++++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 17 deletions(-) diff --git a/docs/0_ExampleSetup.md b/docs/0_ExampleSetup.md index ccca635..27a64b4 100644 --- a/docs/0_ExampleSetup.md +++ b/docs/0_ExampleSetup.md @@ -41,10 +41,14 @@ return [ Create a YAML file in your configuration directory ``` yaml -# config/config/dynamic-search.yaml +# config/packages/dynamic-search.yaml services: - App\DynamicSearch\IndexDefinition\Trinity\Definition: + App\DynamicSearch\IndexDefinition\TrinityDocument: + tags: + - { name: dynamic_search.document_definition_builder } + + App\DynamicSearch\IndexDefinition\Object\Car: tags: - { name: dynamic_search.document_definition_builder } @@ -63,7 +67,7 @@ dynamic_search: index_object: true object_class_names: - Car - index_document: false + index_document: true index_asset: false full_dispatch: document_limit: 10 @@ -98,7 +102,7 @@ dynamic_search: paginator: enabled: true # adapter_class: '' - max_per_page: 1 + max_per_page: 10 normalizer: service: 'lucene_document_key_value_normalizer' #options: @@ -115,26 +119,19 @@ dynamic_search: reference: search ``` -And link it into your main config. To do so update the imports block at the top. Alternatively, you can just add another `imports` at the bottom. - -```yaml -# config/config/config.yaml -imports: - - { resource: dynamic-search.yaml } +Symfony will detect the config in `config/packages` automatically, you do not have to link it. -``` - -## Definition +## Definition for a DataObject ```php getResourceCollectionType() !== 'document') { + return false; + } + + return true; + } + + public function buildDefinition(DocumentDefinitionInterface $definition, array $normalizerOptions): DocumentDefinitionInterface + { + $definition + ->addSimpleDocumentFieldDefinition([ + 'name' => 'id', + 'index_transformer' => [ + 'type' => 'keyword', + ], + 'data_transformer' => [ + 'type' => 'element_id_extractor', + ] + ]) + ->addSimpleDocumentFieldDefinition([ + 'name' => 'path', + 'index_transformer' => [ + 'type' => 'text', + ], + 'data_transformer' => [ + 'type' => 'document_path_generator', + ] + ]) + ->addSimpleDocumentFieldDefinition([ + 'name' => 'title', + 'index_transformer' => [ + 'type' => 'text', + ], + 'data_transformer' => [ + 'type' => 'document_meta_extractor', + 'configuration' => [ + 'type' => 'title', + ], + ] + ]) + ->addSimpleDocumentFieldDefinition([ + 'name' => 'description', + 'index_transformer' => [ + 'type' => 'text', + ], + 'data_transformer' => [ + 'type' => 'document_meta_extractor', + 'configuration' => [ + 'type' => 'description', + ], + ] + ]); + + return $definition; + } +} +``` + ## Indexing -To index your data, just execute: +To index your data, execute following in the command line: ``` bash -bin/console dynamic-search:run +bin/console dynamic-search:run -v ``` +The parameter `-v` will make thoe output more verbose and can help you to find any problems in the config. + ## Test You can test your setup in browser using the URL `/dynamic-search/default/j-search?q=xk140` where the `q` parameter is the search queue.