我有一个Rails应用程序,现在使用ElasticSearch和Tire gem来对模型进行搜索。我想知道如何设置我的应用程序以在模型的某些索引上执行模糊字符串匹配。我已经设置了标题、描述等内容的索引,但是我希望在其中一些上执行模糊字符串匹配,但我不确定应该在哪里进行设置。如果您愿意,请查看下面的代码并提出建议!谢谢!
在控制器中:
在模型中:
在控制器中:
def search
@resource = Resource.search(params[:q], :page => (params[:page] || 1),
:per_page =>15, load: true )
end
在模型中:
class Resource < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
belongs_to :user
has_many :resource_views, :class_name => 'UserResourceView'
has_reputation :votes, source: :user, aggregated_by: :sum
attr_accessible :title, :description, :link, :tag_list, :user_id, :youtubeID
acts_as_taggable
mapping do
indexes :id, :index => :not_analyzed
indexes :title, :analyzer => 'snowball', :boost => 40
indexes :tag_list, :analyzer => 'snowball', :boost => 8
indexes :description, :analyzer => 'snowball', :boost => 2
indexes :user_id, :analyzer => 'snowball'
end
end
:store => 'yes'
参数有什么作用? - phillbaker