Skip to content

Search collections with scopes #397

@pozelli

Description

@pozelli

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions