【发布时间】:2014-03-28 17:43:30
【问题描述】:
我的班级中有一个标签数组,我想将全文搜索范围限定为仅在对象包含标签数组中的多个值之一时才返回对象。不确定这是否可行,因为有多个标签和多个范围值。
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"]) 之一的类别匹配,我希望返回此对象
有没有办法在 Sunspot 中做到这一点?
【问题讨论】:
标签: solr sunspot sunspot-rails sunspot-solr