Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
"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,
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