[gnome-documents] searchbar: Split search into words



commit d2456cd3caa04e59e67dfb22ad9bb4d1b073aad8
Author: Florian MÃllner <fmuellner gnome org>
Date:   Mon Nov 14 01:23:18 2011 +0100

    searchbar: Split search into words
    
    Rather than using the search entry text as a single term when building
    the query, split the text into multiple terms and concatenate the
    results. That way, a search can be refined by adding more words to a
    query, which is generally more useful (possibly with the exception of
    full-text search).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=665158

 src/searchbar.js |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/src/searchbar.js b/src/searchbar.js
index c32eb9a..16cb8bf 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -174,18 +174,22 @@ SearchMatch.prototype = {
     _init: function(params) {
         this.id = params.id;
         this.name = params.name;
+        this._term = '';
+    },
+
+    setFilterTerm: function(term) {
+        this._term = term;
     },
 
     getFilter: function() {
         if (this.id == SearchMatchStock.TITLE)
             return ('fn:contains ' +
                     '(fn:lower-case (tracker:coalesce(nie:title(?urn), nfo:fileName(?urn))), ' +
-                    '"%s")').format(Global.searchController.getString());
+                    '"%s")').format(this._term);
         if (this.id == SearchMatchStock.AUTHOR)
             return ('fn:contains ' +
                     '(fn:lower-case (tracker:coalesce(nco:fullname(?creator), nco:fullname(?publisher))), ' +
-                    '"%s")').format(Global.searchController.getString());
-
+                    '"%s")').format(this._term);
         return '';
     }
 };
@@ -208,6 +212,19 @@ SearchMatchManager.prototype = {
                                        name: _("Author") }));
 
         this.setActiveItemById(SearchMatchStock.ALL);
+    },
+
+    getFilter: function() {
+        let terms = Global.searchController.getTerms();
+        let filters = [];
+
+        for (let i = 0; i < terms.length; i++) {
+            this.forEachItem(function(item) {
+                item.setFilterTerm(terms[i]);
+            });
+            filters.push(Manager.BaseManager.prototype.getFilter.call(this));
+        }
+        return filters.length ? '( ' + filters.join(' && ') + ')' : '';
     }
 };
 
@@ -236,6 +253,10 @@ SearchController.prototype = {
         return this._string;
     },
 
+    getTerms: function() {
+        return this._string.replace(/ +/g, ' ').split(' ');
+    },
+
     setDropownState: function(state) {
         if (this._dropdownState == state)
             return;



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