1

I have a large list of words maybe 300-600 words and I want to make it so that as my user begins typing in a word the app suggest words that it found from my specific list that are close to the spelling that person is giving. Kind of like auto-complete but the list of words is dynamic and specific to that user. Any gems or techniques suggestions on how I can accomplish this?

SupremeA
  • 1,519
  • 3
  • 26
  • 43
  • 1
    One option is using [jQuery Autocomplete control](https://www.devbridge.com/sourcery/components/jquery-autocomplete/). – Nic Nilov Jun 28 '16 at 20:12
  • With a word list that short it probably makes sense to do it on the client-side, i.e. send the entire word list to the browser on page load (versus doing an Ajax request on every keystroke) and then use a component like [typeahead.js](https://twitter.github.io/typeahead.js/) (or the jQuery plugin Nic mentioned) to handle the user interaction. – Jordan Running Jun 28 '16 at 22:50
  • @Jordan even if it has to get the wordlist by going thru an array of objects and pulling the "name" characteristic from each object in the array? – SupremeA Jun 28 '16 at 22:57
  • It's hard to say without knowing the details of your implementation. You're going to have to do that work at some point, whether it's up-front on the server, up-front on the client, or partially on the server upon each keypress. I suggest doing whatever's simplest now and optimizing later if you run into performance problems. (typeahead.js, for its part, ought to work either way, as will many other such components.) – Jordan Running Jun 28 '16 at 23:04
  • ok I think I will create the list in the action before loading the page, thanks for the advice. – SupremeA Jun 28 '16 at 23:17

1 Answers1

1

If you want to do it in ruby you could use a fuzzy match algorithm, like the one used in this gem https://github.com/seamusabshere/fuzzy_match check the example:

>> FuzzyMatch.new(['seamus', 'andy', 'ben']).find('Shamus')
=> "seamus"
neydroid
  • 1,913
  • 13
  • 14