Ruby on rails 思考斯芬克斯:跨多个模型搜索:最佳实践?

Ruby on rails 思考斯芬克斯:跨多个模型搜索:最佳实践?,ruby-on-rails,postgresql,sphinx,thinking-sphinx,Ruby On Rails,Postgresql,Sphinx,Thinking Sphinx,我想添加一个带有类别的jquery自动完成。 该请求将通过Thinking Sphinx搜索多个模型(论坛主题、新闻、用户…) 所以在控制器中,我想它会是这样的 def autocomplete @news = Actu.search(params[:term]).map {|g| {:label => g.title, :category => "Actualités", :id => g.id}} @topics = Topic.search(params[:term]

我想添加一个带有类别的jquery自动完成。 该请求将通过Thinking Sphinx搜索多个模型(论坛主题、新闻、用户…)

所以在控制器中,我想它会是这样的

def autocomplete
 @news = Actu.search(params[:term]).map {|g| {:label => g.title, :category => "Actualités", :id => g.id}}
 @topics = Topic.search(params[:term]).map {|g| {:label => g.title, :category => "Topics", :id => g.id}}
 @anotherModel = ...

 respond_to do |format|
   format.js { render :json => @news+@topics+@anotherModel }
 end
end

这很管用,但是你觉得这些练习怎么样?

你可以试试这个很棒的语法

ThinkingSphinx.search 'pancakes', :classes => [Article, Comment]

阅读更多信息,请访问

您可以尝试这种很棒的语法

ThinkingSphinx.search 'pancakes', :classes => [Article, Comment]

阅读更多信息,请访问

您可以在应用程序中搜索所有索引模型:

ThinkingSphinx.search(params[:term])
然后您可以为每个返回哈希的模型方法定义,比如说
autocomplete\ujson

那么,你的行动呢

def autocomplete
  render :json => ThinkingSphinx.search(params[:term]).map(&:autocomplete_json)
end

您可以搜索应用程序中的所有索引模型:

ThinkingSphinx.search(params[:term])
然后您可以为每个返回哈希的模型方法定义,比如说
autocomplete\ujson

那么,你的行动呢

def autocomplete
  render :json => ThinkingSphinx.search(params[:term]).map(&:autocomplete_json)
end

哦,我已经读了很多次了。。。但我没有看到“应用程序范围的搜索”部分。谢谢哦,我已经读了很多次了。。。但我没有看到“应用程序范围的搜索”部分。谢谢你为什么这么认为?这是用户精心设计的方法。你为什么这么认为?这是用户精心设计的方法。