There is this jquery-autocomplete plugin
which allows you to search for the exact string only..
So lets say this is the data..
[
['apple is good'],
['apple grows on tree'],
['the tree and the apple'],
['red apple'],
['apple tree']
]
Now searching for “apple” should show all.
But when typing “apple tree” it only returns back “apple tree”.
I want it to return the smart results (2,3 and 5).
- “apple grows on tree”
- “the tree and the apple”
- “apple tree”
This means: it should re-evaluate the search again for each word (but filter it from the already filtered results)
This plugin allows you to provide your own search..
what can the refined search which will enable us to smartly search look like?
It needs to ignore whitespace and split the search query in to words to evaluate each word one after the other…
$("#textInputEle").autocomplete({
url:"path/to/data.json",
filter: function(result, filter) {
//whats should this function be?
}
});
You use the
filteroption to supply your own filtering logic.The function you supply takes
resultandfilterparameters. Thefilterparameter is what the user has searched for. Theresultparameter is an item in the list of suggestions. Your function must returntrue(if the suggestion is a match), orfalse(if the suggestion is not a match).The logic to do what you’re trying to accomplish could look something like this:
resultyou’re passed by space (" ") into an array of terms.That would look something like this:
Example: http://jsfiddle.net/ztkX2/1/