]> source.dussan.org Git - nextcloud-server.git/commitdiff
Better search functionality 1693/head
authorJoas Schilling <coding@schilljs.com>
Tue, 11 Oct 2016 08:35:02 +0000 (10:35 +0200)
committerJoas Schilling <coding@schilljs.com>
Tue, 11 Oct 2016 08:35:02 +0000 (10:35 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
settings/js/apps.js

index cd554812ec9d5a92b8fa5711b5a0263946e37c66..5fc366c492149bc784a2cdc11464887cc7565b06 100644 (file)
@@ -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