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

Support for multiple searches of the same index in Multi Search #364

Open
bdesouza opened this issue Jun 10, 2024 · 2 comments
Open

Support for multiple searches of the same index in Multi Search #364

bdesouza opened this issue Jun 10, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@bdesouza
Copy link

Description
Presently, the feature restricts users to a single search operation per index. However, in scenarios involving a Single Table Inheritance model within Rails, there arises a need to execute multiple searches within the same index, each with distinct filter criteria.

The crux of the matter lies in the structure of our input data, which revolves around objects. As such, attempting to define the same key more than once becomes an issue. For example:

multi_search_results = MeiliSearch::Rails.multi_search(
  Book => { q: 'Harry', filter: ['type = "fiction"'] },
  Book => { q: 'Harry', filter: ['type = "documentary"'] }
)

In this instance the first query would be overwritten by the second and result in only one query.

In the ideal world we'd want to emulate what Algolia's rails implementation for multiple_queries

res = client.multiple_queries([
  { indexName: 'categories', query: my_query_string, hitsPerPage: 3 },
  { indexName: 'products', query: my_query_string, filters: '_tags:promotion' },
  { indexName: 'products', query: my_query_string, hitsPerPage: 10 }
])

puts res['results']
@curquiza curquiza added the enhancement New feature or request label Jun 11, 2024
@brunoocasali
Copy link
Member

It makes sense to me, wdyt @ellnix?

In any case @bdesouza feel free to open a PR ❤️

@ellnix
Copy link
Collaborator

ellnix commented Jul 23, 2024

I'm not opposed to it. As it stands, I still think I prefer having a hash so each search has something that can identify it. Using that algolia example I would prefer:

res = client.multiple_queries({
  'categories' => { indexName: 'categories', query: my_query_string, hitsPerPage: 3 },
  'sponsored' => { indexName: 'products', query: my_query_string, filters: '_tags:promotion' },
  'results' => { indexName: 'products', query: my_query_string, hitsPerPage: 10 }
})

And then allow for hash-like access of individual searches:

res[:categories].each do; end # ... render categories
res[:sponsored].each do; end # et cetera

If you have any other requests or ideas, please let me know. I'll be ready to implement this @bdesouza

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

No branches or pull requests

4 participants