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!

beck03076
  • 3,268
  • 2
  • 27
  • 37

1 Answers1

5

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.

Manish Shrivastava
  • 30,617
  • 13
  • 97
  • 101
Mike
  • 1,626
  • 1
  • 12
  • 14
  • LIKE..?.. @Mike, install sphinx search man its amazingly fast. Thanks for your answer. What aboout crowdint/auto-complete? – beck03076 May 04 '12 at 09:23
  • @beck03076 LIKE ? does a mysql search looking for a title like the params[:term} with the % acting as a wildcard. Yes thinking sphinx is fast and i love it and do use it just was not using it for this controller. The crowdint autocomplete is the same exact thing, its just wrapped into a gem with some helper methods. I was using that gem for my autocomplete but i ran into some problems displaying the extra values – Mike May 05 '12 at 00:56
  • So you are saying.. use this..jqueryui ..not the crowdint gem. right? – beck03076 May 05 '12 at 10:52
  • no if you should be fine with the crowdint gem. I was just too lazy to figure out how to get custom data to display using the gem plus i wanted to learn about jquery/javascript – Mike May 06 '12 at 06:52