5

I need helping getting Autocomplete working on my Solr Search bar. Am, using this https://github.com/xponrails/sunspot_autocomplete

Followed the steps & it doesn't work.

I get stuck at my search bar -how do I add it to it, while keeping the params[:search]

Someone else had the same problem, but deleted their code that got it working.

*Does it have to do purely with jquery-ui autocomplete? Or was there something with having to install the plugin a certain way -I'm not sure if I installed it correctly.

Thank You =)

  • Did you ever figure this out? I'm having a problem. i can get everything to appear, and all of the files are loaded and the app loads and i restarted everything...but when i type in the box, nothing happens. the rails server isn't even reacting to input. – afxjzs Oct 31 '12 at 15:09

2 Answers2

0

i just tried it for my project and it worked fine with this steps

  1. all necessary sunspot gems were included and installed (https://github.com/sunspot/sunspot/blob/master/README.md)
  2. autocomplete gem was installed, of course, too (i used little different git path gem 'sunspot_autocomplete', ">= 0.0.3", :git => 'git://github.com/xponrails/sunspot_autocomplete.git' than proposed in manual)
  3. app was restarted after gems added
  4. sunspot generated solr schema.xml was modified (all necessary nodes were added inside blocks <schema name="sunspot" version="1.0"> <types> *here* </types> </fields> *and here* <fields> </schema>)
  5. solr was restarted after schema.xml modified
  6. checked if it started fine with correct! xml (what i mean pointed here)
  7. necessary rows in searchable do; ...; end block for the model were included (it has to be text field and autocompelte field with unique name addressed to text field with :using=>:[text field name] syntax)
  8. model was reindexed after searchable block changes
  9. necessary javascript libraries were included into application.js (i had to copy all js files from gem to app asset folder)
  10. basic styles were included into application.css (same situation as with js files)
  11. assets need to be precompiled (if you try to get it to work in your production environment)
  12. correct autocomplete_text_field was added to view (i had to .html_safe it because it was rendered as raw text)
  13. app was restarted again

and it worked!

but i guess in one or more of this steps you missed something

if the all question is how to add the search field to template - you just need to add this row

<%= autocomplete_text_field("uniq", "field", "http://localhost:8982/solr/", "uniq_field") %> - assuming you have indexed autocomplete :uniq_field, :using => :field and pointed it to the live version of solr (http://localhost:8982/solr/)

if you share with me some code i can point you to something you missed

cheers!

Community
  • 1
  • 1
okliv
  • 3,909
  • 30
  • 47
0

Please find the steps for auto complete. I am going to give an example for auto complete with items.

Step 1: Create a auto complete text field like <%= text_field_with_auto_complete 'item', 'name' %>

step 2: Then call a method named auto_complete_for_item_name.

setp 3: Inside that method get all the rows from the table and keep it in a variable called @items.

step 4: Then call a new method with this @items variable. Like render :inline => "<%= auto_complete_result @items, 'name','med_item'%>"

step 5: In that method put like this content_tag("ul", items.uniq.join)

It will list all the items based on the entered key.

Please correct me if i was wrong..

Thanks & Regards,

Viji Kumar.M

vijikumar
  • 1,805
  • 12
  • 16