[devhelp] Restore the possibility to limit keyword searchs to a specific page



commit 4a824384b3e786c76ab58409f09890ac74dbf105
Author: Frédéric Péters <fpeters 0d be>
Date:   Fri Aug 28 10:47:08 2009 +0200

    Restore the possibility to limit keyword searchs to a specific page

 src/dh-keyword-model.c |   17 +++++++++++++++++
 src/dh-link.c          |   10 ++++++++++
 src/dh-link.h          |    1 +
 3 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/dh-keyword-model.c b/src/dh-keyword-model.c
index 5c21a52..d58dba9 100644
--- a/src/dh-keyword-model.c
+++ b/src/dh-keyword-model.c
@@ -337,9 +337,19 @@ keyword_model_search (DhKeywordModel  *model,
         DhKeywordModelPriv *priv;
         GList              *new_list = NULL, *l;
         gint                hits = 0;
+        gchar              *page_id = NULL;
 
         priv = model->priv;
 
+        /* The search string may be prefixed by a page:foobar qualifier, it
+         * will be matched against the filenames of the hits to limit the
+         * search to pages whose filename is prefixed by "foobar.
+         */
+        if (stringv && g_str_has_prefix(stringv[0], "page:")) {
+                page_id = g_strdup_printf("%s.", stringv[0]+5);
+                stringv++;
+        }
+
         for (l = priv->original_list; l && hits < MAX_HITS; l = l->next) {
                 DhLink   *link;
                 gboolean  found;
@@ -353,6 +363,11 @@ keyword_model_search (DhKeywordModel  *model,
                         continue;
                 }
 
+                if (page_id && 
+                    !g_str_has_prefix(dh_link_get_file_name (link), page_id)) {
+                        continue;
+                }
+
                 if (!case_sensitive) {
                         name = g_ascii_strdown (dh_link_get_name (link), -1);
                 } else {
@@ -384,6 +399,8 @@ keyword_model_search (DhKeywordModel  *model,
                 }
         }
 
+        g_free (page_id);
+
         return g_list_sort (new_list, dh_link_compare);
 }
 
diff --git a/src/dh-link.c b/src/dh-link.c
index f320daa..a93b052 100644
--- a/src/dh-link.c
+++ b/src/dh-link.c
@@ -189,6 +189,16 @@ dh_link_get_page_name (DhLink *link)
 }
 
 const gchar *
+dh_link_get_file_name (DhLink *link)
+{
+        if (link->page) {
+                return link->filename;
+        }
+
+        return "";
+}
+
+const gchar *
 dh_link_get_book_id (DhLink *link)
 {
         if (link->type == DH_LINK_TYPE_BOOK) {
diff --git a/src/dh-link.h b/src/dh-link.h
index aa30df9..ff47b94 100644
--- a/src/dh-link.h
+++ b/src/dh-link.h
@@ -60,6 +60,7 @@ void         dh_link_unref              (DhLink        *link);
 const gchar *dh_link_get_name           (DhLink        *link);
 const gchar *dh_link_get_book_name      (DhLink        *link);
 const gchar *dh_link_get_page_name      (DhLink        *link);
+const gchar *dh_link_get_file_name      (DhLink        *link);
 const gchar *dh_link_get_book_id        (DhLink        *link);
 gchar       *dh_link_get_uri            (DhLink        *link);
 DhLinkFlags  dh_link_get_flags          (DhLink        *link);



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