我有一个 Resource 对象,它具有以下字段: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在标题和描述字段中搜索单词cooking ,并在body中搜索单词cook。
这可能吗?而且因为我是整个搜索游戏的新手,这甚至是个好主意吗?还是我只是一个在火坑上玩弄汽油罐的人?