Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider implementing LocalizedReindexProviderInterface is ignored when reindexing #106

Open
martinsik opened this issue Sep 12, 2016 · 1 comment

Comments

@martinsik
Copy link
Contributor

martinsik commented Sep 12, 2016

I scratched my head around why my search isn't filtered by locale. I'm using DoctrineExtensions Translatable extension and I made a custom reindex provider because I see this is used in ReindexCommand to extract translations for each object.

Well, I didn't expect that calling $this->searchManager->index($object, $locale); ignores $locale because index() method takes only one argument. So, this entire block of code is in fact useless:

$locales = [null];
if ($provider instanceof LocalizedReindexProviderInterface) {
  $locales = $provider->getLocalesForObject($object);
}
try {
  foreach ($locales as $locale) {
    if (null !== $locale) {
      $object = $provider->translateObject($object, $locale);
    }
    $this->searchManager->index($object, $locale);
  }

This all has no effect on entitie's indexed locale because real locale is always extracted from the entity in ObjectToDocumentConverter.

I actually ended up using deprecated call to entity repository that returns all objects that I need to index even though it's probably supposed to throw an error with trigger_error() which is silenced with @ so I doesn't.

I think the entire thing with creating custom providers is useful but now it's too tightly coupled with the entity structure. It has to contain its locale somewhere which is exactly how DoctrineExtensions Translatable extension doesn't work. The LocalizedReindexProviderInterface could work for me when reindexing even though I'd appreciate if providers could check whether they support particular entity class.
Maybe If I could use the same LocalizedReindexProviderInterface provider in IndexListener to grab all translations for particular entity and index them instead of relying on locale property? That would help me a lot.

@danrot
Copy link
Contributor

danrot commented Nov 9, 2016

Can't you simply use our locale configuration, as we did in https://github.com/sulu/sulu/blob/develop/src/Sulu/Bundle/MediaBundle/Resources/config/massive-search/FileVersionMeta.xml#L10 ?

The @ before the trigger_error is wanted, this is how you make Symfony write deprecation messages to the logs :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants