gpt4 book ai didi

ruby-on-rails - Elasticsearch 和 Rails : Using ngram to search for part of a word

转载 作者:数据小太阳 更新时间:2023-10-29 07:37:49 24 4
gpt4 key购买 nike

我正在尝试在我的项目中使用 Elasticsearch-Gem。据我了解:现在已经不需要轮胎 gem 了,还是我错了?

在我的项目中,我有一个搜索(很明显),它目前适用于一个模型。现在我试图避免使用通配符,因为它们不能很好地扩展,但我似乎无法让 ngram-Analyzers 正常工作。如果我搜索整个单词,搜索仍然有效,但部分无效。

class Pictures < ActiveRecord::Base

include Elasticsearch::Model
include Elasticsearch::Model::Callbacks

settings :analysis => {
:analyzer => {
:my_index_analyzer => {
:tokenizer => "keyword",
:filter => ["lowercase", "substring"]
},
:my_search_analyzer => {
:tokenizer => "keyword",
:filter => ["lowercase", "substring"]
}
},
:filter => {
:substring => {
:type => "nGram",
:min_gram => 2,
:max_gram => 50
}
}
} do
mapping do
indexes :title,
:properties => {
:type => "string",
:index_analyzer => 'my_index_analyzer',
:search_analyzer => "my_search_analyzer"
}

也许有人可以给我一些正确方向的提示。

最佳答案

我已经放弃在模型类中定义架构。其实也没什么意义。

这就是我所做的。架构/映射定义 db/文件夹和构建它的 rake 任务。

https://gist.github.com/geordee/9313f4867d61ce340a08

在模型中

def as_indexed_json(options={})
self.as_json(only: [:id, :name, :description, :price])
end

关于ruby-on-rails - Elasticsearch 和 Rails : Using ngram to search for part of a word,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24374394/

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