使用Thinking Sphinx搜索索引模型对象的集合

Mit*_*tya 3 thinking-sphinx ruby-on-rails-3

我有一个arts_to User的技术模型,由Thinking Sphinx索引.

我的模型中还有一个方法返回一个Technique对象数组:

def possible_children(user)
    user.techniques - (self.children + [self])
end
Run Code Online (Sandbox Code Playgroud)

这只是采用用户拥有的技术,减去已经是'self'技术对象的子项的技术,以及'self'本身,并返回剩余的技术对象.

然后在控制器中我实例化可能的子集合,如下所示:

 @possible_children = @technique.possible_children(current_user).search params[:search]
Run Code Online (Sandbox Code Playgroud)

这将返回"未定义的方法'搜索'#"

不确定这是否相关,但发生的控制器不是TechniquesController.

我想要做的是搜索由Model方法返回的任意集合.

有任何想法吗?

如果我需要提供更多信息,请告诉我.谢谢.

pat*_*pat 5

我担心思考狮身人面像是不可能的 - 至少,不是那么简单.你可以做的是使用你想要搜索的对象,获取它们的id,并在过滤器中使用它:

possible_children = @technique.possible_children(current_user)
Technique.search params[:search],
  :with => {:sphinx_internal_id => possible_children.collect(&:id)}
Run Code Online (Sandbox Code Playgroud)

Sphinx有自己的id,但是sphinx_internal_idThinking Sphinx 将数据库中的主键存储为属性.