gpt4 book ai didi

ruby-on-rails - 使用轮胎 gem 为特定领域设置 Elasticsearch 分析器

转载 作者:行者123 更新时间:2023-12-02 01:45:14 25 4
gpt4 key购买 nike

我有一个具有以下字段的资源对象:标题描述正文

使用轮胎 gem 我想使用标准分析器来分析标题描述,但对于正文字段我想使用雪球分析仪。

因此,在我的 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

它将返回 cooking 、煮熟等。

但是我希望能够传递以下查询

curl -XGET localhost:9200/example/_search?q=cooking

我希望elasticsearch在titledescription字段中搜索单词cooking并搜索单词cook正文中。

这可能吗?因为我是整个搜索游戏的新手,所以这是一个好主意吗?或者我只是一个在火坑上玩弄汽油 jar 的人?

最佳答案

当您未在查询中指定字段时,_all字段被搜索。_all 字段包含所有字段的副本,并且它使用默认分析器。可以将默认分析器更改为 Snowball,如 How do I set the default analyzer for elastic search with tire? 中所述。并且还可以控制哪些字段包含在 _all 字段中。

关于ruby-on-rails - 使用轮胎 gem 为特定领域设置 Elasticsearch 分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10815859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com