Lets say I want to create two separate indexes on something like BlogPosts, so that I can do a quick search using one index (for autocomplete purposes for example) then use the other index for full blown search querying.
Is that something I can do with Tire?
so something like this (forgive me if its a little primitive)
class Post < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
index_name 'autocomplete'
mapping do
indexes :title, :analyzer => 'my_ngram_analyzer'
end
index_name 'main'
mapping do
indexes :title
indexes :description
indexes :author
indexes :published_on
end
end
where the callbacks know to add and remove new posts from the appropriate indexes
You can’t do this in Tire, setting two separate indices (and mappings) in one class with the
mappingDSL method.It may be a good idea to use two separate indices, one for auto-completion, another for search. There’s a nice tutorial, StackOverflow answer and even an elasticsearch plugin to get you started.
However, unless you have a lot of data, you’d be able to achieve that even with a single index, using the
multi_fieldtype,matchquery across multiple fields, and potentially an NGram based analyzer.Check out the Autocomplete with Tire tutorial which outlines the approach.
Cross-post from https://github.com/karmi/tire/issues/531