2

我正在使用带有 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

4

1 回答 1

3

问题解决于:

使用属性keyword分析器tags_array

class SomethingWithTag
  # ...
  mapping do
    indexes :tags_array, analyzer: 'keyword'
  end
end
于 2012-12-13T10:10:31.373 回答