@@ -30,7 +30,7 @@ final class MeilisearchService implements SearchService
30
30
private array $ searchableEntities ;
31
31
private array $ entitiesAggregators ;
32
32
private array $ aggregators ;
33
- private array $ classToSerializerGroupMapping ;
33
+ private array $ classToSerializerGroup ;
34
34
private array $ indexIfMapping ;
35
35
36
36
public function __construct (NormalizerInterface $ normalizer , Engine $ engine , array $ configuration )
@@ -42,7 +42,7 @@ public function __construct(NormalizerInterface $normalizer, Engine $engine, arr
42
42
43
43
$ this ->setSearchableEntities ();
44
44
$ this ->setAggregatorsAndEntitiesAggregators ();
45
- $ this ->setClassToSerializerGroupMapping ();
45
+ $ this ->setClassToSerializerGroup ();
46
46
$ this ->setIndexIfMapping ();
47
47
}
48
48
@@ -84,26 +84,26 @@ public function index(ObjectManager $objectManager, $searchable): array
84
84
$ searchable = is_array ($ searchable ) ? $ searchable : [$ searchable ];
85
85
$ searchable = array_merge ($ searchable , $ this ->getAggregatorsFromEntities ($ objectManager , $ searchable ));
86
86
87
- $ searchableToBeIndexed = array_filter (
87
+ $ dataToIndex = array_filter (
88
88
$ searchable ,
89
89
fn ($ entity ) => $ this ->isSearchable ($ entity )
90
90
);
91
91
92
- $ searchableToBeRemoved = [];
93
- foreach ($ searchableToBeIndexed as $ key => $ entity ) {
92
+ $ dataToRemove = [];
93
+ foreach ($ dataToIndex as $ key => $ entity ) {
94
94
if (!$ this ->shouldBeIndexed ($ entity )) {
95
- unset($ searchableToBeIndexed [$ key ]);
96
- $ searchableToBeRemoved [] = $ entity ;
95
+ unset($ dataToIndex [$ key ]);
96
+ $ dataToRemove [] = $ entity ;
97
97
}
98
98
}
99
99
100
- if (count ($ searchableToBeRemoved ) > 0 ) {
101
- $ this ->remove ($ objectManager , $ searchableToBeRemoved );
100
+ if (count ($ dataToRemove ) > 0 ) {
101
+ $ this ->remove ($ objectManager , $ dataToRemove );
102
102
}
103
103
104
104
return $ this ->makeSearchServiceResponseFrom (
105
105
$ objectManager ,
106
- $ searchableToBeIndexed ,
106
+ $ dataToIndex ,
107
107
fn ($ chunk ) => $ this ->engine ->index ($ chunk )
108
108
);
109
109
}
@@ -165,17 +165,17 @@ public function search(
165
165
throw new ObjectIdNotFoundException (sprintf ('There is no "%s" key in the result. ' , self ::RESULT_KEY_OBJECTID ));
166
166
}
167
167
168
+ $ documentId = $ hit [self ::RESULT_KEY_OBJECTID ];
169
+ $ entityClass = $ className ;
170
+
168
171
if (in_array ($ className , $ this ->aggregators , true )) {
169
172
$ objectId = $ hit [self ::RESULT_KEY_OBJECTID ];
170
173
$ entityClass = $ className ::getEntityClassFromObjectId ($ objectId );
171
- $ id = $ className ::getEntityIdFromObjectId ($ objectId );
172
- } else {
173
- $ id = $ hit [self ::RESULT_KEY_OBJECTID ];
174
- $ entityClass = $ className ;
174
+ $ documentId = $ className ::getEntityIdFromObjectId ($ objectId );
175
175
}
176
176
177
177
$ repo = $ objectManager ->getRepository ($ entityClass );
178
- $ entity = $ repo ->find ($ id );
178
+ $ entity = $ repo ->find ($ documentId );
179
179
180
180
if (null !== $ entity ) {
181
181
$ results [] = $ entity ;
@@ -251,15 +251,15 @@ private function setAggregatorsAndEntitiesAggregators(): void
251
251
$ this ->aggregators = array_unique ($ this ->aggregators );
252
252
}
253
253
254
- private function setClassToSerializerGroupMapping (): void
254
+ private function setClassToSerializerGroup (): void
255
255
{
256
256
$ mapping = [];
257
257
258
258
/** @var array $indexDetails */
259
259
foreach ($ this ->configuration ->get ('indices ' ) as $ indexDetails ) {
260
260
$ mapping [$ indexDetails ['class ' ]] = $ indexDetails ['enable_serializer_groups ' ];
261
261
}
262
- $ this ->classToSerializerGroupMapping = $ mapping ;
262
+ $ this ->classToSerializerGroup = $ mapping ;
263
263
}
264
264
265
265
private function setIndexIfMapping (): void
@@ -332,7 +332,7 @@ private function makeSearchServiceResponseFrom(
332
332
333
333
private function canUseSerializerGroup (string $ className ): bool
334
334
{
335
- return $ this ->classToSerializerGroupMapping [$ className ];
335
+ return $ this ->classToSerializerGroup [$ className ];
336
336
}
337
337
338
338
private function assertIsSearchable (string $ className ): void
0 commit comments