【发布时间】:2012-06-04 15:54:49
【问题描述】:
我有一个包含以下字段的资源对象:title、description 和 body。
使用轮胎宝石我想对 title 和 description 使用标准分析器,但对于 body 字段我想使用雪球分析仪。
所以在我的 resource.rb 文件中,我有以下代码:
mapping do
indexes :title, type: 'string', :index => :not_analyzed, :store => true
indexes :description, type: 'string'
indexes :body, type: 'string', :analyzer => 'snowball'
end
def self.search(params)
search_query = params[:query]
tire.search(page: params[:page], per_page: 15) do |s|
s.query { string params[:query], default_operator: "AND"} if params[:query].present?
# do i need another line here specifically for description?
#s.query { string "body:#{params[:query]}", analyzer: 'snowball'} if params[:query].present?
end
end
我将映射中的分析器设置为雪球。我验证这是否有效,因为如果我运行以下命令:
curl -XGET localhost:9200/example/_search?q=body:cook
它将返回烹饪、煮熟等。
但是我希望能够通过以下查询
curl -XGET localhost:9200/example/_search?q=cooking
我希望 elasticsearch 在 title 和 description 字段中搜索单词 cooking 并搜索单词 cook 在正文中。
这可能吗?而且因为我是整个搜索游戏的新手,这甚至是个好主意吗?还是我只是一个在火坑上玩弄汽油罐的人?
【问题讨论】:
标签: ruby-on-rails elasticsearch tire