【发布时间】:2012-01-30 21:38:33
【问题描述】:
我在 Rails 中使用 Sunspot (https://github.com/sunspot/sunspot)。
这是我的模型:
class Item < ActiveRecord::Base
searchable do
boolean :red
boolean :blue
boolean :green
...
end
end
考虑以下搜索:
Item.search
any_of do
with :red, true
with :blue, true
with :green, true
end
end
我如何订购这样的结果:包含所有颜色的项目,然后是包含 2 种颜色的项目,然后是包含 1 种颜色的项目?
注意:这只是一个示例搜索。答案应该考虑所有可能的颜色搜索组合。
更新 1
无法按颜色数量排序。例如,假设您有以下物品:
- 绿色/蓝色
- 绿/红/黑
如果您搜索绿色和蓝色,则第 2 项将位于第 1 项之前。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 solr sunspot