From f2adafe81b00da553d7651e3908870a6e8043451 Mon Sep 17 00:00:00 2001 From: tamsir gueye Date: Sat, 8 Oct 2022 01:01:03 +0000 Subject: [PATCH 1/5] Reindent misplaced lines --- src/DependencyInjection/Configuration.php | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index d16e37b..8f8c2f4 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -29,22 +29,22 @@ public function getConfigTreeBuilder(): TreeBuilder ->arrayPrototype() ->children() ->scalarNode('entity')->end() - ->arrayNode('fields') - ->arrayPrototype() - ->children() - ->scalarNode('entity_attribute')->end() - ->scalarNode('name')->end() - ->scalarNode('type')->end() - ->booleanNode('facet')->end() - ->booleanNode('optional')->end() - ->end() + ->arrayNode('fields') + ->arrayPrototype() + ->children() + ->scalarNode('entity_attribute')->end() + ->scalarNode('name')->end() + ->scalarNode('type')->end() + ->booleanNode('facet')->end() + ->booleanNode('optional')->end() ->end() ->end() - ->scalarNode('default_sorting_field')->isRequired()->cannotBeEmpty()->end() - ->arrayNode('finders') - ->info('Entity specific finders declaration') - ->useAttributeAsKey('name') - ->arrayPrototype() + ->end() + ->scalarNode('default_sorting_field')->isRequired()->cannotBeEmpty()->end() + ->arrayNode('finders') + ->info('Entity specific finders declaration') + ->useAttributeAsKey('name') + ->arrayPrototype() ->children() ->scalarNode('finder_service')->end() ->arrayNode('finder_parameters') From f86117c90a98587749d737030e30c1eef1d0cae5 Mon Sep 17 00:00:00 2001 From: tamsir gueye Date: Sat, 8 Oct 2022 04:31:16 +0000 Subject: [PATCH 2/5] Add token_separators configuration available since Typesense 0.22.0 --- README.md | 15 +++++++++++++++ composer.json | 2 +- src/Client/CollectionClient.php | 3 ++- .../ACSEOTypesenseExtension.php | 1 + src/DependencyInjection/Configuration.php | 4 ++++ src/Manager/CollectionManager.php | 6 +++++- 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 98cf989..752d0e7 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,21 @@ acseo_typesense: type: datetime optional: true # Declare field as optional default_sorting_field: sortable_id # Default sorting field. Must be int32 or float + users: + entity: App\Entity\User + fields: + id: + name: id + type: primary + sortable_id: + entity_attribute: id + name: sortable_id + type: int32 + email: + name: email + type: string + default_sorting_field: sortable_id + token_separators: ['+', '-', '@', '.'] # Optional - This will cause contact+docs-example@typesense.org to be indexed as contact, docs, example, typesense and org. ``` You can use basic types supported by Typesense for your fields : string, int32, float, etc. diff --git a/composer.json b/composer.json index 929438e..e336861 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "scripts": { "typesenseServer": [ "Composer\\Config::disableProcessTimeout", - "docker run -i -p 8108:8108 -v/tmp/typesense-server-data-1c/:/data typesense/typesense:0.21.0 --data-dir /data --api-key=123 --listen-port 8108 --enable-cors" + "docker run -i -p 8108:8108 -v/tmp/typesense-server-data-1c/:/data typesense/typesense:0.22.0 --data-dir /data --api-key=123 --listen-port 8108 --enable-cors" ] } } diff --git a/src/Client/CollectionClient.php b/src/Client/CollectionClient.php index 42b2ebe..ca33821 100644 --- a/src/Client/CollectionClient.php +++ b/src/Client/CollectionClient.php @@ -58,7 +58,7 @@ public function list() return $this->client->collections->retrieve(); } - public function create($name, $fields, $defaultSortingField) + public function create($name, $fields, $defaultSortingField, array $tokenSeparators) { if (!$this->client->isOperationnal()) { return null; @@ -68,6 +68,7 @@ public function create($name, $fields, $defaultSortingField) 'name' => $name, 'fields' => $fields, 'default_sorting_field' => $defaultSortingField, + 'token_separators' => $tokenSeparators, ]); } diff --git a/src/DependencyInjection/ACSEOTypesenseExtension.php b/src/DependencyInjection/ACSEOTypesenseExtension.php index 559e28f..ef3d459 100644 --- a/src/DependencyInjection/ACSEOTypesenseExtension.php +++ b/src/DependencyInjection/ACSEOTypesenseExtension.php @@ -128,6 +128,7 @@ private function loadCollections(array $collections, ContainerBuilder $container 'name' => $name, 'fields' => $config['fields'], 'default_sorting_field' => $config['default_sorting_field'], + 'token_separators' => $config['token_separators'], ]; } } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 8f8c2f4..bfc4061 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -53,6 +53,10 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ->end() ->end() + ->arrayNode('token_separators') + ->defaultValue([]) + ->scalarPrototype()->end() + ->end() ->end() ->end() ->end() diff --git a/src/Manager/CollectionManager.php b/src/Manager/CollectionManager.php index 7fe9cff..3b83acd 100644 --- a/src/Manager/CollectionManager.php +++ b/src/Manager/CollectionManager.php @@ -63,10 +63,14 @@ public function createCollection($collectionDefinitionName) $fields[] = $fieldDefinition; } + //For passing tests + $tokenSeparators = array_key_exists('token_separators', $definition) ? $definition['token_separators'] : []; + $this->collectionClient->create( $definition['typesense_name'], $fields, - $definition['default_sorting_field'] + $definition['default_sorting_field'], + $tokenSeparators ); } } From 3040d98cb7d6cfde30d3fa1e38add4a332594805 Mon Sep 17 00:00:00 2001 From: tamsir gueye Date: Sat, 8 Oct 2022 18:27:02 +0000 Subject: [PATCH 3/5] Change return type to \PHPUnit\Framework\MockObject\MockObject --- tests/Functional/TypesenseInteractionsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Functional/TypesenseInteractionsTest.php b/tests/Functional/TypesenseInteractionsTest.php index 5bbc78b..47e6e67 100644 --- a/tests/Functional/TypesenseInteractionsTest.php +++ b/tests/Functional/TypesenseInteractionsTest.php @@ -308,7 +308,7 @@ private function getMockedEntityManager($books) * * @param $eventType */ - private function getmockedEventCreate($book): \PHPUnit_Framework_MockObject_MockObject + private function getmockedEventCreate($book): \PHPUnit\Framework\MockObject\MockObject { $lifeCycleEvent = $this->createMock(LifecycleEventArgs::class); $lifeCycleEvent->method('getObject')->willReturn($book); From c554c4f6ad9ae58a288fcfe687e4993ddb1cbe29 Mon Sep 17 00:00:00 2001 From: tamsir gueye Date: Sat, 8 Oct 2022 20:23:26 +0000 Subject: [PATCH 4/5] Added symbols_to_index configuration available since Typesense 0.22.0 --- README.md | 1 + src/Client/CollectionClient.php | 3 ++- src/DependencyInjection/ACSEOTypesenseExtension.php | 1 + src/DependencyInjection/Configuration.php | 4 ++++ src/Manager/CollectionManager.php | 6 ++++-- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 752d0e7..e107583 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ acseo_typesense: type: datetime optional: true # Declare field as optional default_sorting_field: sortable_id # Default sorting field. Must be int32 or float + symbols_to_index: ['+'] # Optional - You can add + to this list to make the word c++ indexable verbatim. users: entity: App\Entity\User fields: diff --git a/src/Client/CollectionClient.php b/src/Client/CollectionClient.php index ca33821..893c4c9 100644 --- a/src/Client/CollectionClient.php +++ b/src/Client/CollectionClient.php @@ -58,7 +58,7 @@ public function list() return $this->client->collections->retrieve(); } - public function create($name, $fields, $defaultSortingField, array $tokenSeparators) + public function create($name, $fields, $defaultSortingField, array $tokenSeparators, array $symbolsToIndex) { if (!$this->client->isOperationnal()) { return null; @@ -69,6 +69,7 @@ public function create($name, $fields, $defaultSortingField, array $tokenSeparat 'fields' => $fields, 'default_sorting_field' => $defaultSortingField, 'token_separators' => $tokenSeparators, + 'symbols_to_index' => $symbolsToIndex ]); } diff --git a/src/DependencyInjection/ACSEOTypesenseExtension.php b/src/DependencyInjection/ACSEOTypesenseExtension.php index ef3d459..be411a2 100644 --- a/src/DependencyInjection/ACSEOTypesenseExtension.php +++ b/src/DependencyInjection/ACSEOTypesenseExtension.php @@ -129,6 +129,7 @@ private function loadCollections(array $collections, ContainerBuilder $container 'fields' => $config['fields'], 'default_sorting_field' => $config['default_sorting_field'], 'token_separators' => $config['token_separators'], + 'symbols_to_index' => $config['symbols_to_index'], ]; } } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index bfc4061..958b5ff 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -57,6 +57,10 @@ public function getConfigTreeBuilder(): TreeBuilder ->defaultValue([]) ->scalarPrototype()->end() ->end() + ->arrayNode('symbols_to_index') + ->defaultValue([]) + ->scalarPrototype()->end() + ->end() ->end() ->end() ->end() diff --git a/src/Manager/CollectionManager.php b/src/Manager/CollectionManager.php index 3b83acd..98ba249 100644 --- a/src/Manager/CollectionManager.php +++ b/src/Manager/CollectionManager.php @@ -63,14 +63,16 @@ public function createCollection($collectionDefinitionName) $fields[] = $fieldDefinition; } - //For passing tests + //to pass the tests $tokenSeparators = array_key_exists('token_separators', $definition) ? $definition['token_separators'] : []; + $symbolsToIndex = array_key_exists('symbols_to_index', $definition) ? $definition['symbols_to_index'] : []; $this->collectionClient->create( $definition['typesense_name'], $fields, $definition['default_sorting_field'], - $tokenSeparators + $tokenSeparators, + $symbolsToIndex ); } } From 34e7738a172498a39eaa3e2fa4d936dd33febc8d Mon Sep 17 00:00:00 2001 From: tamsir gueye Date: Sat, 8 Oct 2022 20:45:02 +0000 Subject: [PATCH 5/5] code quality improvements --- src/Client/CollectionClient.php | 2 +- src/Manager/CollectionManager.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client/CollectionClient.php b/src/Client/CollectionClient.php index 893c4c9..b28caf4 100644 --- a/src/Client/CollectionClient.php +++ b/src/Client/CollectionClient.php @@ -69,7 +69,7 @@ public function create($name, $fields, $defaultSortingField, array $tokenSeparat 'fields' => $fields, 'default_sorting_field' => $defaultSortingField, 'token_separators' => $tokenSeparators, - 'symbols_to_index' => $symbolsToIndex + 'symbols_to_index' => $symbolsToIndex, ]); } diff --git a/src/Manager/CollectionManager.php b/src/Manager/CollectionManager.php index 98ba249..e9e92a3 100644 --- a/src/Manager/CollectionManager.php +++ b/src/Manager/CollectionManager.php @@ -65,7 +65,7 @@ public function createCollection($collectionDefinitionName) //to pass the tests $tokenSeparators = array_key_exists('token_separators', $definition) ? $definition['token_separators'] : []; - $symbolsToIndex = array_key_exists('symbols_to_index', $definition) ? $definition['symbols_to_index'] : []; + $symbolsToIndex = array_key_exists('symbols_to_index', $definition) ? $definition['symbols_to_index'] : []; $this->collectionClient->create( $definition['typesense_name'],