使用elasticsearch来过滤带有空格的标签
我正在使用轮胎(https://github.com/karmi/tire)与mongoid。 这是我的模型定义:
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
问题解决于:
将keyword
分析器用于tags_array
属性:
class SomethingWithTag # ... mapping do indexes :tags_array, analyzer: 'keyword' end end
- Carrierwave_Direct的direct_upload_form_for为FileUploader返回未定义的方法`model_name’:Class
- ActionView :: Template :: Error(在heroku上没有将Fixnum隐式转换为String
- Mongoid:如何查询value为nil的所有对象?
- Heroku / Unicorn上的重复导轨错误 – “执行过期”,一个ActionView :: Template :: Error
- 由于* _attributes后缀的forms,强参数,嵌套属性和Mongoid似乎不起作用?
- Rails Mongoid无法进行身份validation – 失败,错误13:“未授权查询my_db.my_collection”
- 覆盖Mongoid模型的setter和getter
- Ruby模型输出id作为对象oid
- Mongoid has_and_belongs_to_many关联