Search code examples
ruby-on-rails-3autocompletefull-text-searchsphinxthinking-sphinx

Best auto complete/suggest for a search form in rails 3


I have a rails app that uses the following,

  • rails 3.1,
  • ruby 1.9.2,
  • mysql,
  • sphinx search,
  • will paginate,
  • thinking sphinx,
  • I opted not to use a gem for a simple login, so no devise, no authlogic. Login from scratch, using BCrypt for encrypting passwords.
  • JQuery.

Now, this app does nothing but handles a products catalog. When I say products catalog, not just a simple one. It handles, all the features, categories, brands.

There is a master text search functionality on all the product titles and features listed in 2 mysql tables. TITLES and FEATURES. Search is working fine and relevant.

We have decided to include auto-complete/auto-suggest in to our app.

Questions:


  1. Should I use a gem or build it from scratch?. please give your reason

  2. If I should use a gem, which one to use, does that gem is up to date and has a forum to support anytime?.

  3. We think, auto-complete/suggest on "titles" table would be fine when compared to adding auto-complete/suggest on both "titles" and "features" tables. Your comments on that?

  4. What is it, auto-suggest or auto-complete?


(Like, there is PAT ALLAN and BARRY HUNTER for thinking sphinx and sphinx search,Gosh! its their dedication to support that make users sleep sound)

I stated the elements of my app in detail, please advice me !

Thanks!


Solution

  • jqueryui is a great resource.

    here is a demo of autocomplete, you can view the source to see how to implement on your server. http://jqueryui.com/demos/autocomplete/

    the javascript sends a term=TERM to your controller. Mine is setup like this:

    def autocomplete
      @movies= Movie.select("id, title").where("title LIKE ?", "#{params[:term]}%").limit(20)
      @hash = []
      @movies.each do |movie|
        @hash << {"label" => movie.title, "id" => movie.id}
      end
      render :json => @hash
    end
    

    customize to how you see fit.