Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update configuration options available in Typesense v0.22.0 #60

Merged
merged 5 commits into from Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
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
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
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
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
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
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
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