Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
"Any word" filter for YUI Autocomplete
/*
* Use the following in the "resultFilters" option when creating a YUI 3 Autocomplete
* widget. This will return matches when *any* of the words in the query string match.
* This is opposed to the default "wordMatch", which matches *all* words in the
* query string.
*/
function matchAnyWord(query, results) {
var WordBreak = Y.Text.WorkBreak,
options = { ignoreCase: 1 },
queryWords = WordBreak.getUniqueWords(query, options);
return Y.Array.filter(results, function (result) {
// Convert resultWords array to a hash for fast lookup.
var resultWords = Y.Array.hash(WordBreak.getUniqueWords(result.text,
options));
return Y.Array.some(queryWords, function (word) {
return Y.Object.owns(resultWords, word);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.