太阳黑子/ Solr范围由数组字段

时间:2014-03-28 17:43:31

标签: solr sunspot sunspot-rails sunspot-solr

我的班级中有一个标签数组,我想将全文搜索范围限定为只返回对象,如果它们包含tags数组中的多个值之一。不确定这是否可行,因为有多个标签和多个范围值。

class Video
  include Sunspot::Mongoid2

  field :categories, type: Array, default: [] # array of strings
  field :description, type: String, default: ""
  field :title, type: String, default: ""

  searchable do #these fields will be indexed by sunspot/solr
    text :title
    text :description
    string :categories # this seems wrong but there is no array field type?????
  end
end

这似乎是错误的,因为没有array字段类型,字符串数组与string不同。

然而,我想要的全文查询是这样的:

search = Video.search do
  fulltext params[:q] do
    fields :title, :description
  end
  with(:categories, ["Netflix", "Amazon"])
end
@videos = search.results

同样,这是因为categories通常会有多个值,因此对象可能具有:

video.categories = ["Horror", "Drama", "Netlfix"]

如果fulltext与上述类别匹配with(:categories, ["Netflix", "Amazon"])

中的至少一个,我希望返回此对象

有没有办法在太阳黑子中做到这一点?

1 个答案:

答案 0 :(得分:3)

跑耙太阳黑子:solr:reindex给出了解决这个问题的线索。它说类别不是多值的。所以以下解决了它:

  searchable do #these fields will be indexed by sunspot/solr
    text :title
    text :description
    string :categories, multiple: true
  end

和reindex和查询工作。

相关问题