[gnome-boxes] Allow search with multiple terms



commit 0628e998bd0607b80dc1a974ff3231d0195183dc
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Jan 25 16:06:00 2013 +0100

    Allow search with multiple terms
    
    A search like "foo bar" now means name contains "foo" and "bar".
    This is nicer, and what you expect from e.g. gnome-shell search.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685229

 src/collection.vala |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/src/collection.vala b/src/collection.vala
index 2cc5ac6..2ce8b8e 100644
--- a/src/collection.vala
+++ b/src/collection.vala
@@ -29,14 +29,23 @@ private class Boxes.Collection: GLib.Object {
 }
 
 private class Boxes.CollectionFilter: GLib.Object {
-    public string text;
+    string [] terms;
 
-    public bool filter (CollectionItem item) {
-        if (text == null)
-            return true;
+    public string text {
+        set {
+            terms = value.split(" ");
+            for (int i = 0; i < terms.length; i++)
+                terms[i] = canonicalize_for_search (terms[i]);
+        }
+    }
 
-        var text = text.casefold ();
-        return item.name.casefold ().index_of (text) != -1;
+    public bool filter (CollectionItem item) {
+        var name = canonicalize_for_search (item.name);
+        foreach (var term in terms) {
+            if (! (term in name))
+                return false;
+        }
+        return true;
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]