ruby-on-rails-3acts-as-taggable-onfuzzy-search

Fuzzy tag matching with acts-as-taggable


So I'm using acts_as_taggable on a model. I'd like to be able to find tags with some sort of a %LIKE% matching, but I'm not sure how.

My current code:

@companies = Company.tagged_with(@query, :any => true)

doing this doesn't work:

tagged_with("%#{@query}%", :any => true)

Any ideas?


Solution

  • Solved by fetching the tags manually first

      tags = Tag.where("name LIKE ?", "%#{@query}%").pluck(:name)
      @companies = Company.tagged_with(tags, :any => true)
    

    However, this required my to create an empty Tag model, which isn't created by acts_as_taggable.

    Maybe not the best solution, but it works :)
    I'll rather do this "hack", then to write my own tagging models.