gpt4 book ai didi

ruby - 使用 elasticsearch 过滤带空格的标签

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

我正在使用带有 mongoid 的轮胎 (https://github.com/karmi/tire)。这是我的模型定义:

class SomethingWithTag
include Mongoid::Document
include Mongoid::Timestamps
field :tags_array, type: Array

include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :tags_array, type: :array, index: :not_analyzed
end
end

假设我有一个文档 {tags_array: ["hello world"]}。然后下面的查询工作正常:

SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello"] }
SomethingWithTag.tire.search { filter :terms, :tags_array => ["world"] }
SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello", "world"] }

但以下不返回任何结果:

SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello world"] }

我应该怎么做才能让它发挥作用?

编辑:这是要测试的一小段代码:http://pastebin.com/n1rUtK3e

最佳答案

问题解决时间:

tags_array 属性使用 keyword 分析器:

class SomethingWithTag
# ...
mapping do
indexes :tags_array, analyzer: 'keyword'
end
end

关于ruby - 使用 elasticsearch 过滤带空格的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11822019/

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