@@ -57,9 +57,7 @@ public function __construct(NormalizerInterface $normalizer, Engine $engine, arr
57
57
58
58
public function isSearchable ($ className ): bool
59
59
{
60
- if (is_object ($ className )) {
61
- $ className = ClassUtils::getClass ($ className );
62
- }
60
+ $ className = $ this ->getBaseClassName ($ className );
63
61
64
62
return in_array ($ className , $ this ->searchableEntities , true );
65
63
}
@@ -76,6 +74,8 @@ public function getConfiguration(): Collection
76
74
77
75
public function searchableAs (string $ className ): string
78
76
{
77
+ $ className = $ this ->getBaseClassName ($ className );
78
+
79
79
$ indexes = new Collection ($ this ->getConfiguration ()->get ('indices ' ));
80
80
$ index = $ indexes ->firstWhere ('class ' , $ className );
81
81
@@ -207,7 +207,8 @@ public function count(string $className, string $query = '', array $searchParams
207
207
208
208
public function shouldBeIndexed (object $ entity ): bool
209
209
{
210
- $ className = ClassUtils::getClass ($ entity );
210
+ $ className = $ this ->getBaseClassName ($ entity );
211
+
211
212
$ propertyPath = $ this ->indexIfMapping [$ className ];
212
213
213
214
if (null !== $ propertyPath ) {
@@ -221,6 +222,21 @@ public function shouldBeIndexed(object $entity): bool
221
222
return true ;
222
223
}
223
224
225
+ private function getBaseClassName (mixed $ object_or_class ): string
226
+ {
227
+ foreach ($ this ->searchableEntities as $ class ) {
228
+ if (is_a ($ object_or_class , $ class , true )) {
229
+ return $ class ;
230
+ }
231
+ }
232
+
233
+ if (is_object ($ object_or_class )) {
234
+ return ClassUtils::getClass ($ object_or_class );
235
+ }
236
+
237
+ return $ object_or_class ;
238
+ }
239
+
224
240
private function setSearchableEntities (): void
225
241
{
226
242
$ searchable = [];
@@ -313,7 +329,7 @@ private function makeSearchServiceResponseFrom(
313
329
foreach (array_chunk ($ entities , $ this ->configuration ->get ('batchSize ' )) as $ chunk ) {
314
330
$ searchableEntitiesChunk = [];
315
331
foreach ($ chunk as $ entity ) {
316
- $ entityClassName = ClassUtils:: getClass ($ entity );
332
+ $ entityClassName = $ this -> getBaseClassName ($ entity );
317
333
318
334
$ searchableEntitiesChunk [] = new SearchableEntity (
319
335
$ this ->searchableAs ($ entityClassName ),
0 commit comments