Skip to content

Commit 95310cc

Browse files
authored
Merge branch 'master' into feature/collection-prefix
2 parents c74b724 + f4d1475 commit 95310cc

File tree

7 files changed

+58
-19
lines changed

7 files changed

+58
-19
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ acseo_typesense:
8585
type: datetime
8686
optional: true # Declare field as optional
8787
default_sorting_field: sortable_id # Default sorting field. Must be int32 or float
88+
symbols_to_index: ['+'] # Optional - You can add + to this list to make the word c++ indexable verbatim.
89+
users:
90+
entity: App\Entity\User
91+
fields:
92+
id:
93+
name: id
94+
type: primary
95+
sortable_id:
96+
entity_attribute: id
97+
name: sortable_id
98+
type: int32
99+
email:
100+
name: email
101+
type: string
102+
default_sorting_field: sortable_id
103+
token_separators: ['+', '-', '@', '.'] # Optional - This will cause contact+docs-example@typesense.org to be indexed as contact, docs, example, typesense and org.
88104
```
89105
90106
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
@@ -13,7 +13,7 @@
1313
"php": "^7.4||^8.0",
1414
"doctrine/orm": "~2.8,>=2.8.0",
1515
"symfony/framework-bundle": "^3.4|^4.3|^5|^6.0",
16-
"symfony/http-client-contracts": "^1.0|^2.0",
16+
"symfony/http-client-contracts": "^1.0|^2.0|^3.0",
1717
"typesense/typesense-php": "^4.1.0",
1818
"php-http/curl-client": "^2.2",
1919
"monolog/monolog": "^2.3",

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
@@ -138,6 +138,8 @@ private function loadCollections(array $collections, ContainerBuilder $container
138138
'name' => $name,
139139
'fields' => $config['fields'],
140140
'default_sorting_field' => $config['default_sorting_field'],
141+
'token_separators' => $config['token_separators'],
142+
'symbols_to_index' => $config['symbols_to_index'],
141143
];
142144
}
143145
}

src/DependencyInjection/Configuration.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ public function getConfigTreeBuilder(): TreeBuilder
3131
->children()
3232
->scalarNode('collection_name')->end()
3333
->scalarNode('entity')->end()
34-
->arrayNode('fields')
35-
->arrayPrototype()
36-
->children()
37-
->scalarNode('entity_attribute')->end()
38-
->scalarNode('name')->end()
39-
->scalarNode('type')->end()
40-
->booleanNode('facet')->end()
41-
->booleanNode('optional')->end()
42-
->end()
34+
->arrayNode('fields')
35+
->arrayPrototype()
36+
->children()
37+
->scalarNode('entity_attribute')->end()
38+
->scalarNode('name')->end()
39+
->scalarNode('type')->end()
40+
->booleanNode('facet')->end()
41+
->booleanNode('optional')->end()
4342
->end()
4443
->end()
45-
->scalarNode('default_sorting_field')->isRequired()->cannotBeEmpty()->end()
46-
->arrayNode('finders')
47-
->info('Entity specific finders declaration')
48-
->useAttributeAsKey('name')
49-
->arrayPrototype()
44+
->end()
45+
->scalarNode('default_sorting_field')->isRequired()->cannotBeEmpty()->end()
46+
->arrayNode('finders')
47+
->info('Entity specific finders declaration')
48+
->useAttributeAsKey('name')
49+
->arrayPrototype()
5050
->children()
5151
->scalarNode('finder_service')->end()
5252
->arrayNode('finder_parameters')
@@ -55,6 +55,14 @@ public function getConfigTreeBuilder(): TreeBuilder
5555
->end()
5656
->end()
5757
->end()
58+
->arrayNode('token_separators')
59+
->defaultValue([])
60+
->scalarPrototype()->end()
61+
->end()
62+
->arrayNode('symbols_to_index')
63+
->defaultValue([])
64+
->scalarPrototype()->end()
65+
->end()
5866
->end()
5967
->end()
6068
->end()

src/Manager/CollectionManager.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ public function createAllCollections()
4848
}
4949
}
5050

51-
public function deleteCollextion($collectionDefinitionName)
51+
public function deleteCollection($collectionDefinitionName)
5252
{
5353
$definition = $this->collectionDefinitions[$collectionDefinitionName];
5454
$this->collectionClient->delete($definition['typesense_name']);
5555
}
5656

57+
public function deleteCollextion($collectionDefinitionName)
58+
{
59+
return $this->deleteCollection($collectionDefinitionName);
60+
}
61+
5762
public function createCollection($collectionDefinitionName)
5863
{
5964
$definition = $this->collectionDefinitions[$collectionDefinitionName];
@@ -64,10 +69,16 @@ public function createCollection($collectionDefinitionName)
6469
$fields[] = $fieldDefinition;
6570
}
6671

72+
//to pass the tests
73+
$tokenSeparators = array_key_exists('token_separators', $definition) ? $definition['token_separators'] : [];
74+
$symbolsToIndex = array_key_exists('symbols_to_index', $definition) ? $definition['symbols_to_index'] : [];
75+
6776
$this->collectionClient->create(
6877
$definition['typesense_name'],
6978
$fields,
70-
$definition['default_sorting_field']
79+
$definition['default_sorting_field'],
80+
$tokenSeparators,
81+
$symbolsToIndex
7182
);
7283
}
7384
}

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)