[gnome-news/wip/gbsneto/improvements: 5/12] search: fix search



commit 914cd1437bb428a6128ea4f11440ad4e27de622a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Mar 5 16:19:56 2016 -0300

    search: fix search
    
    It works now. Thanks to Carlos Garnacho for the
    unvaluable help.

 gnomenews/toolbar.py |    2 +-
 gnomenews/tracker.py |   28 +++++++++++++++++-----------
 gnomenews/view.py    |    3 +++
 3 files changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/gnomenews/toolbar.py b/gnomenews/toolbar.py
index 287edef..ab258b2 100644
--- a/gnomenews/toolbar.py
+++ b/gnomenews/toolbar.py
@@ -80,7 +80,7 @@ class Toolbar(GObject.GObject):
     def _search_changed(self, entry, data=None):
         if entry.get_text_length() > 0:
             self.set_state(ToolbarState.SEARCH_VIEW)
-            self.header_bar.set_title(_("Searching for %s") % entry.get_text())
+            self.header_bar.set_title(_('Searching for "%s"') % entry.get_text())
         else:
             self.set_state(ToolbarState.MAIN)
             self.header_bar.set_title(_("News"))
diff --git a/gnomenews/tracker.py b/gnomenews/tracker.py
index 4c4250c..4bc6721 100644
--- a/gnomenews/tracker.py
+++ b/gnomenews/tracker.py
@@ -237,29 +237,35 @@ class Tracker(GObject.GObject):
         """
         query = """
         SELECT
-          nie:url(?msg) AS url
-          nie:title(?msg) AS title
-          nco:fullname(?creator) AS fullname
-          nie:url(?website) AS author_homepage
-          nco:emailAddress(?email) AS author_email
-          nie:contentCreated(?msg) AS date_created
-          nmo:htmlMessageContent(?msg) AS content
-          nmo:isRead(?msg) AS is_read
+          nie:url(?msg) AS ?url
+          nie:title(?msg) AS ?title
+          nco:fullname(?creator) AS ?fullname
+          nie:url(?website) AS ?author_homepage
+          nco:emailAddress(?email) AS ?author_email
+          nie:contentCreated(?msg) AS ?date_created
+          nmo:htmlMessageContent(?msg) AS ?content
+          nmo:isRead(?msg) AS ?is_read
           { ?msg a mfo:FeedMessage; """
 
         if channel:
-            query += """nmo:communicationChannel ?chan;"""
+            query += """
+                nmo:communicationChannel ?chan;
+                ?chan nie:url "%s" . """
 
         query += """
                  fts:match "%s" .
-                 ?chan nie:url "%s" .
             OPTIONAL { ?msg nco:creator ?creator .
                        OPTIONAL { ?creator nco:hasEmailAddress ?email } .
                        OPTIONAL { ?creator nco:websiteUrl ?website }}
           }
         ORDER BY fts:rank(?msg)
         LIMIT %d
-        """ % (text, channel, amount)
+        """
+
+        if channel:
+            query = query % (text, channel, amount)
+        else:
+            query = query % (text, amount)
 
         results = self.sparql.query(query)
         ret = []
diff --git a/gnomenews/view.py b/gnomenews/view.py
index 3cd0b0b..89d2594 100644
--- a/gnomenews/view.py
+++ b/gnomenews/view.py
@@ -358,6 +358,9 @@ class SearchView(GenericFeedsView):
     def update_search(self):
         [self.flowbox.remove(old_feed) for old_feed in self.flowbox.get_children()]
 
+        if len(self.search_query) is 0:
+            return
+
         posts = self.tracker.get_text_matches(self.search_query, 10)
         [self._add_a_new_preview(post) for post in posts]
         self.show_all()


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