【问题标题】:Thinking sphinx - how to index type of STI model思考狮身人面像 - 如何索引 STI 模型的类型
【发布时间】:2016-08-08 15:42:59
【问题描述】:

有什么方法可以索引 STI 模型的类型(Ruby 中的多态模型关联)而不是它本身?比如我有一个模特Comment

class Comment < ActiveRecord::Base
  belongs_to :commenter, polymorphic: true
  ...
end

是否可以让 sphinx 索引 commenters 而不是 comments

具体来说,不是sphinx.conf 的样子

source comment_core_0
{
  ...
  sql_query = SELECT SQL_NO_CACHE comments.id * 60 + 2 AS id, 
    'Comment' AS sphinx_internal_class_name, 
    comments.id AS sphinx_internal_id, 
    'Comment' AS sphinx_internal_class
    ...
}

我希望sphinx.conf 看起来像:

source comment_core_0
{
  ...
  sql_query = SELECT SQL_NO_CACHE comments.commenter_id * 60 + 2 AS id, 
    commenter_type AS sphinx_internal_class_name, 
    comments.commenter_id AS sphinx_internal_id, 
    commenter_type AS sphinx_internal_class
    ...
}

谢谢

【问题讨论】:

    标签: ruby-on-rails ruby thinking-sphinx


    【解决方案1】:

    恐怕 Thinking Sphinx 无法做到这一点 - 它的构建是为了将索引映射到单个模型。此外,在您描述的情况下(如果您要直接在 Sphinx 而不是 TS 中进行类似的工作),如果评论者有多个评论,您最终可能会得到重复的记录。

    最好为每种评论者类型设置索引并同时搜索所有这些索引。

    【讨论】:

      猜你喜欢
      • 2013-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多