In order to assign tags, users of my software search their existing tags (which is populated in an autocomplete). I want to index this search in Sphinx so the tag search is ultra responsive. I have seen posts on how to index a Model's tags with sphinx which helps when trying to find all the objects with that tag name, but I want to index the tag search itself for people searching for existing tags.
I am trying to use Sphinx for this search
Lead.tag_counts(:conditions => ["tags.name like ?", 'accounting%'])
Which produces the SQL
SELECT tags.id, tags.name, COUNT() AS count FROM
tags
LEFT OUTER JOIN taggings ON tags.id = taggings.tag_id AND taggings.context = 'tags' INNER JOIN leads ON leads.id = taggings.taggable_id WHERE ((taggings.taggable_type = 'Lead' AND tags.name like 'accounting%' )) GROUP BY tags.id, tags.name HAVING COUNT()0
I assume I have to add indexes to the Tag model to allow the below to work, but not quite sure what they should be.
Tag.sphinx_leads_scope.search(params[:tag])
Thanks, John-Paul