diff --git a/README.md b/README.md index 98cf989..e107583 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,22 @@ 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: + 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..b28caf4 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, array $symbolsToIndex) { if (!$this->client->isOperationnal()) { return null; @@ -68,6 +68,8 @@ public function create($name, $fields, $defaultSortingField) 'name' => $name, '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 559e28f..be411a2 100644 --- a/src/DependencyInjection/ACSEOTypesenseExtension.php +++ b/src/DependencyInjection/ACSEOTypesenseExtension.php @@ -128,6 +128,8 @@ private function loadCollections(array $collections, ContainerBuilder $container 'name' => $name, '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 d16e37b..958b5ff 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') @@ -53,6 +53,14 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ->end() ->end() + ->arrayNode('token_separators') + ->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 7fe9cff..e9e92a3 100644 --- a/src/Manager/CollectionManager.php +++ b/src/Manager/CollectionManager.php @@ -63,10 +63,16 @@ public function createCollection($collectionDefinitionName) $fields[] = $fieldDefinition; } + //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'] + $definition['default_sorting_field'], + $tokenSeparators, + $symbolsToIndex ); } } 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);