Rails、Sphinx (thinking_sphinx) 和关联排序

发布于 2024-11-18 07:13:59 字数 818 浏览 3 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§对你不离不弃 2024-11-25 07:13:59

也许您应该在 Define_index 块中添加:

has :skin_id

,然后在搜索时按其进行过滤。像这样的东西:

Item.search(:with => {:skin_id => skin.id}, :order_by => 'ratings ASC')

Perhaps you should have in your define_index block:

has :skin_id

and then, when searching, filter by that. Something like this:

Item.search(:with => {:skin_id => skin.id}, :order_by => 'ratings ASC')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文