Search code examples
ruby-on-railsautocompletesolrsunspotsunspot-rails

autocomplete in Solr and sunspot


I'm building a website with RoR and I use Sunspot and the solr Search Engine. I needed to use autocomplete functionality but I couldn't. I knew that Solr has a new thing called suggester but I don't know how to use this with sunspot and in a rails app.

I found a gem called sunspot_autocomplete and I followed what was written, but when I try to reindex I get this error :

rake aborted!
RSolr::Error::Http - 400 Bad Request
Error: ERROR:unknown field 'tags_ac'

The model that is searchable called Experience and I put this block in it

searchable do
  text :tags, :boost => 3
  text :title, :boost => 2
  text :tips
  autocomplete :tags, :using => :tags
end 

Finally I found this blog that it sounds good but I don't understand it :(

http://www.binrand.com/post/3338898-autocomplete-solr-architecture-rails-3-2-solr-1-4-with-sunspot-solr-gem.html

I need your help in putting the autocomplete functionality in my app. Thanks A lot :)

Update: I finally fixed and made a demo here in the search box.


Solution

  • i had the same "problem" =)

    just ensure you have correct schema.xml with "autocomplete" type and fields defined at your solr schema path http://localhost:8982/solr/admin/file/?file=schema.xml (assuming you have local default sunspot dev environment)

    for me, i had other one from other project ran at this path (and port)

    you can see which one you have in the top of http://localhost:8982/solr/admin/ as SolrHome

    hope it helped!