Skip to content

Commit

Permalink
Merge pull request #60 from tamsirgueye/master
Browse files Browse the repository at this point in the history
Update configuration options available in Typesense v0.22.0
  • Loading branch information
npotier authored Nov 24, 2022
2 parents db2b2f4 + 34e7738 commit e44574e
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 18 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
4 changes: 3 additions & 1 deletion src/Client/CollectionClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
]);
}

Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/ACSEOTypesenseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}
}
Expand Down
36 changes: 22 additions & 14 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion src/Manager/CollectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
2 changes: 1 addition & 1 deletion tests/Functional/TypesenseInteractionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e44574e

Please sign in to comment.