spicavigo
spicavigo

Reputation: 4224

Javascript Auto Suggest

Is there a library available for Auto Suggest/Complete for cases like the following

Searching for "Vir" returns both "West Virginia" and "Virginia"

Thanks

EDIT

Sorry for not explaining it more. In the problem above, I do not want a "contains" search, but a prefix search on word boundaries. So "est" should not return "West Virginia", but "wes" or "vir" should.

The list is around 500 items large.

Proposed Solution

I modified the trie implementation by Mike de Boer https://github.com/mikedeboer/trie to solve this. I split an item on word boundaries and stored each word in the trie. For the last letter of each word I stored the index of the item that the word came from in the trie node. When user searches, I return a list of indices and then get the corresponding items from the main list.

What do you guys think?

Upvotes: 1

Views: 1223

Answers (4)

spicavigo
spicavigo

Reputation: 4224

I modified the trie implementation by Mike de Boer https://github.com/mikedeboer/trie to solve this. I split an item on word boundaries and stored each word in the trie. For the last letter of each word I stored the index of the item that the word came from in the trie node. When user searches, I return a list of indices and then get the corresponding items from the main list.

Upvotes: 0

Jonas Geiregat
Jonas Geiregat

Reputation: 5432

First, you should try to use google or search previous question before asking such a straight forward question.

To answer your question, you could use jquery-ui wich has amoung many other widgets one called Autocomplete. If you're familair with JQuery this should be pretty easy to implement.

http://jqueryui.com/demos/autocomplete/

Upvotes: 2

bondythegreat
bondythegreat

Reputation: 1409

you can use jquery autocomplete. ah, you've answered that already by yourself! http://bit.ly/uXHRR0

Upvotes: 0

Related Questions