From c8874fc47810ebcaee15a843e281b203d0e118a2 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 27 Sep 2013 18:40:05 +0100 Subject: [PATCH] Try to make package searching more responsive --- html/js/melpa.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/html/js/melpa.js b/html/js/melpa.js index 17beca31..f327023c 100644 --- a/html/js/melpa.js +++ b/html/js/melpa.js @@ -21,7 +21,7 @@ }) .then(function (info) { - var calculateSourceURL = function(name, recipe) { + var calculateSourceURL = function(name, recipe) { if (recipe.fetcher == "github") { return (/\//.test(recipe.repo) ? "https://github.com/" : "https://gist.github.com/") + recipe.repo; } else if (recipe.fetcher == "wiki" && !recipe.files) { @@ -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; }; }; });