【发布时间】:2014-11-24 19:38:17
【问题描述】:
我正在尝试使用 Rails (3.2.8)、Tire 和 ElasticSearch 创建自定义映射。
我希望“标题”和“描述”成为唯一可搜索/索引的属性......但是,我似乎无法完成这项工作:
下面是我的模型:
class BlogPost < ActiveRecord::Base
attr_accessible :title, :description, :attachment, :attachment_thumbnail
include Tire::Model::Search
include Tire::Model::Callbacks
tire.mapping do
indexes :id, :type => 'integer', :index => :not_analyzed, :include_in_all => false
indexes :attachment, :type => 'string', :index => :not_analyzed, :include_in_all => false
indexes :attachment_thumbnail, :type => 'string', :index => :not_analyzed, :include_in_all => false
indexes :title, analyzer: 'snowball', boost: 100
indexes :description, analyzer: 'snowball', boost: 100
end
def self.search(params)
tire.search(load: true, page: params[:page], per_page: 15) do
query do
boolean do
must { string params[:query], default_operator: "AND" } if params[:query].present?
end
end
end
end
end
【问题讨论】:
标签: ruby-on-rails elasticsearch ruby-on-rails-3.2 tire