Try to make package searching more responsive

This commit is contained in:
Steve Purcell 2013-09-27 18:40:05 +01:00
parent 71c217d98c
commit c8874fc478

View file

@ -101,12 +101,16 @@
});
$scope.packageMatcher = function(term) {
var t = term && term.toLowerCase();
var matchp = function(v) {
return v && v.toLowerCase().indexOf(t) != -1;
var searchTextCache = {};
var searchText = function(pkg) {
var v = searchTextCache[pkg.name];
if (!v)
v = searchTextCache[pkg.name] = _([pkg.name, pkg.description, pkg.source, pkg.version, pkg.sourceURL]).compact().invoke('toLowerCase').valueOf().join(' ');
return v;
};
return function(pkg) {
if (!term || !term.match(/\S/)) return true;
return matchp(pkg.name) || matchp(pkg.description) || matchp(pkg.source) || matchp(pkg.version) || matchp(pkg.sourceURL);
return searchText(pkg).indexOf(t) != -1;
};
};
});