Open
Description
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
returnsCat
s andDog
s)
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.