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

Index-first search #341

Open
ellnix opened this issue Feb 28, 2024 · 1 comment
Open

Index-first search #341

ellnix opened this issue Feb 28, 2024 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@ellnix
Copy link
Collaborator

ellnix commented Feb 28, 2024

Description
Currently the starting point of any search is a Rails model, which is not conducive to things like shared indexes or multiple indexes.

In the current state of this gem a model may have multiple indexes but only the primary index will be searchable in the way we want it to Model.search ... and there is no convenient way to search others (while receiving ActiveRecord instances).

In addition it's hard to keep track of what models share an index, making it inconvenient (and currently impossible) to rebuild a shared index safely.

I propose we create a new type of resource in a rails app called an index:

  • defined in files in app/indexes/*_index.rb
  • pointing to models similar to Rails associations searches :books, class_name: 'Ebook' do ... end
  • searchable and capable of returning polymorphic results (AnimalIndex.search returns Cats and Dogs)

Basic example

# app/indexes/animal_index.rb
class AnimalIndex < MeiliSearch::Rails::Base
  searches :cats do
    attributes :name, :meow
  end
  
  searches :whales, class_name: 'PacificWhale' do
    attribute :label, :last_spotted, :voice
  end

  searches :tigers, if: :captured?
end
# app/indexes/location_index.rb
class LocationIndex < MeiliSearch::Rails::Base
  searches :restaurants do
    attributes :name, :cousine, '_geo'
  end

  searches :public_restrooms do
    attribute '_geo'
  end

  searches :landmarks do
    attributes :name, :type, '_geo'
  end
end

LocationIndex.search('', filter: { '_geoRadius(1, 2, 3)' })

P. S.: I am not suggesting removing the current meilisearch block syntax, just adding another way to search.

@ellnix ellnix added the enhancement New feature or request label Feb 28, 2024
@botbotbotbotboot
Copy link

+1

@ellnix ellnix added this to the 0.13 milestone Feb 29, 2024
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

2 participants