Thinking sphinx - 如何索引 STI 模型的类型
Thinking sphinx - how to index type of STI model
有没有办法索引 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
...
}
谢谢
恐怕这对于 Thinking Sphinx 是不可能的 - 它被构建为期望索引映射到单个模型。此外,在您所描述的情况下(如果您要直接在 Sphinx 中而不是在 TS 中进行此类工作),如果评论者有多个评论,您最终可能会得到重复的记录。
您最好为每种评论者类型创建索引并同时搜索所有这些索引。
有没有办法索引 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
...
}
谢谢
恐怕这对于 Thinking Sphinx 是不可能的 - 它被构建为期望索引映射到单个模型。此外,在您所描述的情况下(如果您要直接在 Sphinx 中而不是在 TS 中进行此类工作),如果评论者有多个评论,您最终可能会得到重复的记录。
您最好为每种评论者类型创建索引并同时搜索所有这些索引。