From: Joas Schilling Date: Tue, 11 Oct 2016 08:35:02 +0000 (+0200) Subject: Better search functionality X-Git-Tag: v10.0.2~107^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d831156d78d953ebc3cd16ea03f508649fdc1a9c;p=nextcloud-server.git Better search functionality Signed-off-by: Joas Schilling --- diff --git a/settings/js/apps.js b/settings/js/apps.js index ed2bae2dae3..ddb8db002d5 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -494,6 +494,24 @@ OC.Settings.Apps = OC.Settings.Apps || { ); }, + /** + * Splits the query by spaces and tries to find all substring in the app + * @param {string} string + * @param {string} query + * @returns {boolean} + */ + _search: function(string, query) { + var keywords = query.split(' '), + stringLower = string.toLowerCase(), + found = true; + + _.each(keywords, function(keyword) { + found = found && stringLower.indexOf(keyword) !== -1; + }); + + return found; + }, + filter: function(query) { var $appList = $('#apps-list'), $emptyList = $('#apps-list-empty'); @@ -510,17 +528,17 @@ OC.Settings.Apps = OC.Settings.Apps || { // App Name var apps = _.filter(OC.Settings.Apps.State.apps, function (app) { - return app.name.toLowerCase().indexOf(query) !== -1; + return OC.Settings.Apps._search(app.name, query); }); // App ID apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) { - return app.id.toLowerCase().indexOf(query) !== -1; + return OC.Settings.Apps._search(app.id, query); })); // App Description apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) { - return app.description.toLowerCase().indexOf(query) !== -1; + return OC.Settings.Apps._search(app.description, query); })); // Author Name @@ -540,9 +558,9 @@ OC.Settings.Apps = OC.Settings.Apps || { } } }); - return authors.join(' ').toLowerCase().indexOf(query) !== -1; + return OC.Settings.Apps._search(authors.join(' '), query); } - return app.author.toLowerCase().indexOf(query) !== -1; + return OC.Settings.Apps._search(app.author, query); })); // App status