useranon
useranon

Reputation: 29514

Rails Sunspot search for items tagged with the tag

I am working in Rails 3. In one of my model, I have

acts_as_taggable_on :hashtags

and for indexing I have

searchable :auto_index => false do
  text :tags do
    "#{hashtags.map(&:name).to_sentence}"
  end
  integer :tag_ids, :references => ActsAsTaggableOn::Tag, :multiple => true do
    [hashtag_ids].flatten
  end
end

And when I do Sunspot search for items tagged for this model

Sunspot.search(Modelname) do
  with :tag_ids, 1
end

the above doesn't list the items

But the same works for other models which has

acts_as_taggable_on :tags

How to fix this issue. Also in taggings the context is tags(other models) and hashtags(the model with acts_as_taggable_on :hashtags).

Upvotes: 1

Views: 891

Answers (1)

Laura Popa
Laura Popa

Reputation: 456

Try something like this:

 searchable do
  string  :hashtag_list, :multiple => true, :stored => true
 end

Then this should return results

ModelName.solr_search do
 with :hashtag_list, ["tag1", "tag2"]
end 

Upvotes: 1

Related Questions