2
我在我的类中有一个标签数组,我想将全文搜索的范围限制为只返回对象,如果它们包含tags数组中的一个值。不确定这是否可能,因为有多个标签和多个范围值。太阳黑子/ Solr按数组字段范围
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"])
有没有办法在太阳黑子做到这一点?