@@ -30,7 +30,7 @@ final class MeilisearchService implements SearchService
3030 private array $ searchableEntities ;
3131 private array $ entitiesAggregators ;
3232 private array $ aggregators ;
33- private array $ classToSerializerGroupMapping ;
33+ private array $ classToSerializerGroup ;
3434 private array $ indexIfMapping ;
3535
3636 public function __construct (NormalizerInterface $ normalizer , Engine $ engine , array $ configuration )
@@ -42,7 +42,7 @@ public function __construct(NormalizerInterface $normalizer, Engine $engine, arr
4242
4343 $ this ->setSearchableEntities ();
4444 $ this ->setAggregatorsAndEntitiesAggregators ();
45- $ this ->setClassToSerializerGroupMapping ();
45+ $ this ->setClassToSerializerGroup ();
4646 $ this ->setIndexIfMapping ();
4747 }
4848
@@ -84,26 +84,26 @@ public function index(ObjectManager $objectManager, $searchable): array
8484 $ searchable = is_array ($ searchable ) ? $ searchable : [$ searchable ];
8585 $ searchable = array_merge ($ searchable , $ this ->getAggregatorsFromEntities ($ objectManager , $ searchable ));
8686
87- $ searchableToBeIndexed = array_filter (
87+ $ dataToIndex = array_filter (
8888 $ searchable ,
8989 fn ($ entity ) => $ this ->isSearchable ($ entity )
9090 );
9191
92- $ searchableToBeRemoved = [];
93- foreach ($ searchableToBeIndexed as $ key => $ entity ) {
92+ $ dataToRemove = [];
93+ foreach ($ dataToIndex as $ key => $ entity ) {
9494 if (!$ this ->shouldBeIndexed ($ entity )) {
95- unset($ searchableToBeIndexed [$ key ]);
96- $ searchableToBeRemoved [] = $ entity ;
95+ unset($ dataToIndex [$ key ]);
96+ $ dataToRemove [] = $ entity ;
9797 }
9898 }
9999
100- if (count ($ searchableToBeRemoved ) > 0 ) {
101- $ this ->remove ($ objectManager , $ searchableToBeRemoved );
100+ if (count ($ dataToRemove ) > 0 ) {
101+ $ this ->remove ($ objectManager , $ dataToRemove );
102102 }
103103
104104 return $ this ->makeSearchServiceResponseFrom (
105105 $ objectManager ,
106- $ searchableToBeIndexed ,
106+ $ dataToIndex ,
107107 fn ($ chunk ) => $ this ->engine ->index ($ chunk )
108108 );
109109 }
@@ -165,17 +165,17 @@ public function search(
165165 throw new ObjectIdNotFoundException (sprintf ('There is no "%s" key in the result. ' , self ::RESULT_KEY_OBJECTID ));
166166 }
167167
168+ $ documentId = $ hit [self ::RESULT_KEY_OBJECTID ];
169+ $ entityClass = $ className ;
170+
168171 if (in_array ($ className , $ this ->aggregators , true )) {
169172 $ objectId = $ hit [self ::RESULT_KEY_OBJECTID ];
170173 $ 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 );
175175 }
176176
177177 $ repo = $ objectManager ->getRepository ($ entityClass );
178- $ entity = $ repo ->find ($ id );
178+ $ entity = $ repo ->find ($ documentId );
179179
180180 if (null !== $ entity ) {
181181 $ results [] = $ entity ;
@@ -251,15 +251,15 @@ private function setAggregatorsAndEntitiesAggregators(): void
251251 $ this ->aggregators = array_unique ($ this ->aggregators );
252252 }
253253
254- private function setClassToSerializerGroupMapping (): void
254+ private function setClassToSerializerGroup (): void
255255 {
256256 $ mapping = [];
257257
258258 /** @var array $indexDetails */
259259 foreach ($ this ->configuration ->get ('indices ' ) as $ indexDetails ) {
260260 $ mapping [$ indexDetails ['class ' ]] = $ indexDetails ['enable_serializer_groups ' ];
261261 }
262- $ this ->classToSerializerGroupMapping = $ mapping ;
262+ $ this ->classToSerializerGroup = $ mapping ;
263263 }
264264
265265 private function setIndexIfMapping (): void
@@ -332,7 +332,7 @@ private function makeSearchServiceResponseFrom(
332332
333333 private function canUseSerializerGroup (string $ className ): bool
334334 {
335- return $ this ->classToSerializerGroupMapping [$ className ];
335+ return $ this ->classToSerializerGroup [$ className ];
336336 }
337337
338338 private function assertIsSearchable (string $ className ): void
0 commit comments