-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Description
I want to discuss the use of collections in meilisearch-rails.
One could use the filterable attributes for simple cases. For example:
Article.ms_search('awesome', filter: "release_date > #{(Time.now - 1.day).to_i}")
Now, since meilisearch-rails already makes queries to the database to find items by the primary keys, my idea is meilisearch-rails could fully support collections as well, making it possible to run fewer queries in more advanced scenarios.
Basic example
Let's start with a simple example to illustrate:
# This works, because the collection "Article.where('id < 50')" is used as "meilisearch_options[:type]" at "meilisearch_options[:type].where(condition_key => hit_ids)"
Article.where('id < 50').ms_search(Article.first.name)
# This does not work ("undefined method `where' for #<Meilisearch::Rails::Pagination::Kaminari:0x0000560335df3660>")
Article.ms_search(Article.first.name).where('id < 50')
I think the order of scopes should not matter.
Perhaps the ms_search method could just return something like this: "where(id: hit_ids)"
In this case, correct me if I'm missing something, I think the pagination might not be necessary in this gem at all, it could be handled externally.
For example:
Article.ms_search('awesome').joins(:user).merge(User.admin).page(3).per(10)
would be equivalent to:
Article.where(id: [1, 10, 15]).joins(:user).merge(User.admin).page(3).per(10)
Other
- I consider this issue is related to:
- Issue Polymorphic shared indexes #340 - Polymorphic shared indexes: The discussion is about an option to search an index and return a polymorphic collection with results from multiple models.
- Issue Index-first search #341 - Index-first search: The discussion is about the fact "the starting point of any search is a Rails model, which is not conducive to things like shared indexes or multiple indexes". It proposes the creation of a new type of resource in a Rails app called an index, capable of returning polymorphic results (AnimalIndex.search returns Cats and Dogs).
- Issue Support for multiple searches of the same index in Multi Search #364 - Support for multiple searches of the same index in Multi Search
- Issue Support federated search #389 - Support federated search: The federated multi-search makes it possible to use a single pagination for different models. The support for pagination backends (Kaminari and will_paginate) is missing at FederatedSearchResult.
- PR Allow custom group names in multi search #391 - Allow custom group names in multi search
- PR Add federated search #393 - Add federated search