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

Multiple indexes per Entity #269

Open
B-Galati opened this issue Oct 29, 2018 · 4 comments
Open

Multiple indexes per Entity #269

B-Galati opened this issue Oct 29, 2018 · 4 comments

Comments

@B-Galati
Copy link

Hello !

  • Symfony version: 4.1.6
  • Algolia Search Bundle version: 3.3.2
  • Algolia Client Version: 1.27.0
  • Language Version: 7.2.7

Description

I was trying to index the same entity twice with 2 indices name.
My goal was to leverage instantsearch.js sortBySelector widget.

So I did something like this:

algolia_search:
    indices:
        - name: publication
          class: App\Entity\Publication
          index_if: isPublished
          enable_serializer_groups: true

        - name: publication_sort_by_date_desc
          class: App\Entity\Publication
          index_if: isPublished
          enable_serializer_groups: true

It looks like it was working as expected at 1st glance but no.
Only the last declared indice is pushed to Algolia. The others are not updated anymore: no clear, no update, no import, etc.

Is this something that could be interesting to support within the bundle? Am I going to the wrong direction and this feature should be implemented differently?
At the end, if this is a bad idea, an error message to prevent creating such a config could really nice for DX. Perhaps I missed something in the doc.

Cheers and thanks for this awesome bundle 👍

@nunomaduro
Copy link
Contributor

Thanks for reporting this issue @B-Galati. I am going to run a quick test on the next couple days and I will keep you posted! 👍

@nunomaduro nunomaduro self-assigned this Oct 29, 2018
@B-Galati
Copy link
Author

Thanks :-)

@nunomaduro
Copy link
Contributor

Thanks for the wait. The problem comes out of the method Algolia\SearchBundle\IndexManager::setClassToIndexMapping:

    private function setClassToIndexMapping()
    {
        $mapping = [];
        foreach ($this->configuration['indices'] as $indexName => $indexDetails) {
            $mapping[$indexDetails['class']] = $indexName;
        }

        $this->classToIndexMapping = $mapping;
    }

The result using your configuration:

array:1 [▼
  "App\Entity\Publication" => "publication_sort_by_date_desc"
]

Having more than one index per Entity seems a real cool feature. For now, we do have other Pull Requests to merge before coding this feature. Let's keep this open for later. 👍

@nunomaduro nunomaduro changed the title Index the same entity twice with different indice name Multiple indexes per Entity Oct 31, 2018
@B-Galati
Copy link
Author

B-Galati commented Nov 5, 2018

@nunomaduro Thanks for the heads up!

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

No branches or pull requests

2 participants