Skip to content

Commit e44574e

Browse files
authored
Merge pull request acseo#60 from tamsirgueye/master
Update configuration options available in Typesense v0.22.0
2 parents db2b2f4 + 34e7738 commit e44574e

File tree

7 files changed

+52
-18
lines changed

7 files changed

+52
-18
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ acseo_typesense:
8383
type: datetime
8484
optional: true # Declare field as optional
8585
default_sorting_field: sortable_id # Default sorting field. Must be int32 or float
86+
symbols_to_index: ['+'] # Optional - You can add + to this list to make the word c++ indexable verbatim.
87+
users:
88+
entity: App\Entity\User
89+
fields:
90+
id:
91+
name: id
92+
type: primary
93+
sortable_id:
94+
entity_attribute: id
95+
name: sortable_id
96+
type: int32
97+
email:
98+
name: email
99+
type: string
100+
default_sorting_field: sortable_id
101+
token_separators: ['+', '-', '@', '.'] # Optional - This will cause contact+docs-example@typesense.org to be indexed as contact, docs, example, typesense and org.
86102
```
87103
88104
You can use basic types supported by Typesense for your fields : string, int32, float, etc.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"scripts": {
3535
"typesenseServer": [
3636
"Composer\\Config::disableProcessTimeout",
37-
"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"
37+
"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"
3838
]
3939
}
4040
}

src/Client/CollectionClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function list()
5858
return $this->client->collections->retrieve();
5959
}
6060

61-
public function create($name, $fields, $defaultSortingField)
61+
public function create($name, $fields, $defaultSortingField, array $tokenSeparators, array $symbolsToIndex)
6262
{
6363
if (!$this->client->isOperationnal()) {
6464
return null;
@@ -68,6 +68,8 @@ public function create($name, $fields, $defaultSortingField)
6868
'name' => $name,
6969
'fields' => $fields,
7070
'default_sorting_field' => $defaultSortingField,
71+
'token_separators' => $tokenSeparators,
72+
'symbols_to_index' => $symbolsToIndex,
7173
]);
7274
}
7375

src/DependencyInjection/ACSEOTypesenseExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ private function loadCollections(array $collections, ContainerBuilder $container
128128
'name' => $name,
129129
'fields' => $config['fields'],
130130
'default_sorting_field' => $config['default_sorting_field'],
131+
'token_separators' => $config['token_separators'],
132+
'symbols_to_index' => $config['symbols_to_index'],
131133
];
132134
}
133135
}

src/DependencyInjection/Configuration.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ public function getConfigTreeBuilder(): TreeBuilder
2929
->arrayPrototype()
3030
->children()
3131
->scalarNode('entity')->end()
32-
->arrayNode('fields')
33-
->arrayPrototype()
34-
->children()
35-
->scalarNode('entity_attribute')->end()
36-
->scalarNode('name')->end()
37-
->scalarNode('type')->end()
38-
->booleanNode('facet')->end()
39-
->booleanNode('optional')->end()
40-
->end()
32+
->arrayNode('fields')
33+
->arrayPrototype()
34+
->children()
35+
->scalarNode('entity_attribute')->end()
36+
->scalarNode('name')->end()
37+
->scalarNode('type')->end()
38+
->booleanNode('facet')->end()
39+
->booleanNode('optional')->end()
4140
->end()
4241
->end()
43-
->scalarNode('default_sorting_field')->isRequired()->cannotBeEmpty()->end()
44-
->arrayNode('finders')
45-
->info('Entity specific finders declaration')
46-
->useAttributeAsKey('name')
47-
->arrayPrototype()
42+
->end()
43+
->scalarNode('default_sorting_field')->isRequired()->cannotBeEmpty()->end()
44+
->arrayNode('finders')
45+
->info('Entity specific finders declaration')
46+
->useAttributeAsKey('name')
47+
->arrayPrototype()
4848
->children()
4949
->scalarNode('finder_service')->end()
5050
->arrayNode('finder_parameters')
@@ -53,6 +53,14 @@ public function getConfigTreeBuilder(): TreeBuilder
5353
->end()
5454
->end()
5555
->end()
56+
->arrayNode('token_separators')
57+
->defaultValue([])
58+
->scalarPrototype()->end()
59+
->end()
60+
->arrayNode('symbols_to_index')
61+
->defaultValue([])
62+
->scalarPrototype()->end()
63+
->end()
5664
->end()
5765
->end()
5866
->end()

src/Manager/CollectionManager.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ public function createCollection($collectionDefinitionName)
6363
$fields[] = $fieldDefinition;
6464
}
6565

66+
//to pass the tests
67+
$tokenSeparators = array_key_exists('token_separators', $definition) ? $definition['token_separators'] : [];
68+
$symbolsToIndex = array_key_exists('symbols_to_index', $definition) ? $definition['symbols_to_index'] : [];
69+
6670
$this->collectionClient->create(
6771
$definition['typesense_name'],
6872
$fields,
69-
$definition['default_sorting_field']
73+
$definition['default_sorting_field'],
74+
$tokenSeparators,
75+
$symbolsToIndex
7076
);
7177
}
7278
}

tests/Functional/TypesenseInteractionsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ private function getMockedEntityManager($books)
308308
*
309309
* @param $eventType
310310
*/
311-
private function getmockedEventCreate($book): \PHPUnit_Framework_MockObject_MockObject
311+
private function getmockedEventCreate($book): \PHPUnit\Framework\MockObject\MockObject
312312
{
313313
$lifeCycleEvent = $this->createMock(LifecycleEventArgs::class);
314314
$lifeCycleEvent->method('getObject')->willReturn($book);

0 commit comments

Comments
 (0)