开发者

Sunspot indexing and searching tags returns everything

I am using act_as_taggable_on for tagging in our projects, along with sunspot/solr for searching.

We get a strange unexpected result. First our setup (short version):

Model:

Class Person
  has_many :projects

  searchable do
    string :project_tags, :multiple => true do
      projects.map { |p| p.tag_list}.flatten
    end
  end

Taglist is a method from act_as_taggable_on which returns an array of tags for each projects (f.e. ["foo", "bar"]). We index the project tags for the project members.

When, in our controller, we do:

Person.search() do
   with(:project_tags).any_of(para开发者_开发知识库ms[:tags])
end

This returns the right people. So far so good.

The Problem

We want to be able to search for multiple tags. So, per sunspot instructions, we pass along an array. The code looks roughly like this:

@tags_array= params[:tags].split(/ /)
Person.search() do
   with(:project_tags).any_of(@tags_array)
end

Now Sunspot gives us every person as a result, no matter what tags we use! We have been testing this in the console like crazy, but can't understand where we are going wrong.

Any help would be appreciated!

Erwin


Ok we "solved" this ourselves and i'll report it back here in case anyone comes looking with the same question.

Somehow Sunspot doesn't like @tags_array in our search declaration, after some testing any @variable will not work. As soon as we changed it to:

tags_array= params[:tags].split(/ /)
Person.search() do
   with(:project_tags).any_of(tags_array)
end

it worked.

Cheers,
Erwin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜