Description
I'm excited to try Meilisearch, so I'm happy there's a symfony bundle! Sadly the project I picked to try it out on uses Doctrine's Single Table Inheritance, and this confuses the meili:import
command, or more specifically Services\MeiliSearchService::isSearchable()
.
Under Doctrine's single table inheritance method, we create multiple entity classes that inherit from a root entity in the normal PHP way (class MyEntityType extends BaseEntity…
), and then a so-called discriminator column saves which type an entity really is, and Doctrine takes care of hydrating the right entity type when you load things from the parent type's repository. To give an example, I've got an app where I've got a Card entity, and its two subtypes are Article and Link. Both Article and Link have all the (searchable) properties of Card, but Articles have a content blob and Links have a URL to a site. With my previous search solution, I indexed Card so that I could search all cards together, which makes sense in this app -- the differences between the entities are in how they're displayed, not in what we browse and search for.
The problem seems to be that isSearchable()
does a string comparison of entity class names against a list of configured classes, rather than using PHP's instanceof
operator. This means that although all my entities are descendants of Card, they're actually Link or Article entities so isSearchable
returns false and nothing ever gets into my index. If I configure each entity to have its own index, then… well they'd be in separate indices and not searchable as one thing, which is what I'd like to continue doing.
If I were to try to resolve this myself, I'd change the isSearchable method to do something like this
public function isSearchable($className): bool
{
if (is_object($className)) {
$className = ClassUtils::getClass($className);
}
foreach ($this->searchableEntities as $searchableEntity) {
if ($className instanceof $searchableEntity) {
return true;
}
}
return false;
}
However I've not tested this, and I'm not familiar enough with the bundle or its uses to know if this could cause problems for other users, so I'm reluctant to submit a PR. If you think it's an acceptable change, I could try my hand at it though!