0
我把輪胎搜索在我的模型:ActiveRelation其中()輪胎搜索
class Name < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :name, type: 'string', analyzer: 'snowball'
indexes :lang, type: 'string'
indexes :private, type: 'boolean'
indexes :id, index: :not_analyzed, type: 'integer'
end
end
然後,當我執行:
txt = params[:search]
Name.tire.search page: page, per_page: PER_PAGE do
string txt
end
如果效果很好,但我怎麼鏈更加搜索條件像:
Name.where(private: false, lang: ['ru', 'en'], id: [1,2,3,4])
我試圖做的:
@results = Name.tire.search per_page: per, page: page do
query do
boolean do
must { string txt }
must { term 'names.id', ids } unless ids.blank?
must { term 'names.private', false }
must { term 'names.lang', lang }
end
end
end
但它沒有返回任何結果..
感謝差異,部分它幫助我! –