Rails、Sphinx (thinking_sphinx) 和关联排序
我有 3 个模型:
Stats (belongs_to :item)
t.integer :skin_id
t.integer :item_id
t.integer :rating
Item (has_many :stats)
和
Skin (has_many :stats)
使用 thinking_sphinx 我想为项目创建一个单独的索引,按特定的:skin_id 的评级排序,
所以,我正在尝试:
define_index 'sort_by_rate' do
indexes stats(:rating), :as => :ratings, :sortable => true
end
但这将为所有项目生成一个索引:skin_id(在 Stat 模型中),不适用于特定的皮肤。
换句话说,我需要收集所有项目,按 Stat. rating 排序,其中 Stat.skin_id == 1 (例如)。
这是 SQL 的示例:
"SELECT `stats`.* FROM `stats` INNER JOIN `items` ON `items`.`id` = `stats`.`item_id` WHERE `stats`.`skin_id` = 1 ORDER BY rating DESC"
非常感谢任何解决方案!
I have 3 models:
Stats (belongs_to :item)
t.integer :skin_id
t.integer :item_id
t.integer :rating
Item (has_many :stats)
and
Skin (has_many :stats)
Using thinking_sphinx i want to create a separate index, for items, sorted by :rating for particular :skin_id
So, i'm trying to:
define_index 'sort_by_rate' do
indexes stats(:rating), :as => :ratings, :sortable => true
end
But this, will generate an index for all :skin_id (in the Stat model), not for particular one.
In other words, i need to gather all items, sorted by Stat.rating, with Stat.skin_id == 1 (for example).
Here is the example of SQL:
"SELECT `stats`.* FROM `stats` INNER JOIN `items` ON `items`.`id` = `stats`.`item_id` WHERE `stats`.`skin_id` = 1 ORDER BY rating DESC"
ANy solutions is very appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您应该在 Define_index 块中添加:
,然后在搜索时按其进行过滤。像这样的东西:
Perhaps you should have in your define_index block:
and then, when searching, filter by that. Something like this: