Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict';
/*
IMPORTANT: requires Underscore.js (http://underscorejs.org)
Usage: ng-repeat="item in items | fuzzyFilter: searchText"
*/
var app = angular.module('app', []);
app.filter('fuzzyFilter', function () {
return function (items, searchText) {
if (!searchText) {
return items;
}
var searchWords = searchText.split(' ');
return _.filter(items, function (item) {
var itemValues = _.values(item);
var itemText = itemValues.join(' ');
var lowerCasedItemText = itemText.toLowerCase();
return _.every(searchWords, function (searchWord) {
var lowerCasedSearchWord = searchWord.toLowerCase();
return lowerCasedItemText.search(lowerCasedSearchWord) !== -1;
});
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.