我有一个Rails应用程序,其中我使用Thinking-Sphinx进行搜索,使用ActsAsTaggableOn进行标记。我希望能够将当前选定的标记包含在我的搜索查询中。我试过以下几种方法,但没有让它起作用。
在我的控制器里:
def show
@team_tags = @team.ideas.tag_counts_on(:tags)
if params[:tag]
@ideas = @team.ideas.search(params[:search], :conditions => { tags: "tag" })
else
@ideas = @team.ideas.search(params[:search])
end
end我的Idea模型索引:
ThinkingSphinx::Index.define :idea, :with => :real_time do
[...]
indexes tags.name, :as => :tags
has user_id, type: :integer
has team_id, type: :integer
[...]
end这给了我以下错误:
ActionView::Template::Error (index idea_core: query error: no field 'tags' found in schema当我选择一个标记时,我的URLs如下所示:
/teams/1/tags/tag那么,我应该怎么做才能让Thinking-Sphinx和ActsAsTaggableOn一起工作呢?
发布于 2014-07-24 20:18:38
您所拥有的字段只适用于SQL支持的索引,而不是实时索引。
在这种情况下,您想要做的是在模型中创建一个方法,将所有标记名称作为一个字符串返回:
def tag_names
tags.collect(&:name).join(' ')
end然后您可以在索引定义中引用这一点:
indexes tag_names, :as => :tags一旦您这样做了,您将需要重新生成狮身人面像索引,因为您已经更改了结构:rake ts:regenerate。
https://stackoverflow.com/questions/24890271
复制相似问题