]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Add the exclude flag to notmuch_query_search_threads
authorMark Walters <markwalters1009@gmail.com>
Thu, 1 Mar 2012 22:30:38 +0000 (22:30 +0000)
committerDavid Bremner <bremner@debian.org>
Fri, 2 Mar 2012 12:28:39 +0000 (08:28 -0400)
Add the NOTMUCH_MESSAGE_FLAG_EXCLUDED flag to
notmuch_query_search_threads. Implemented by inspecting the tags
directly in _notmuch_thread_create/_thread_add_message rather than as
a Xapian query for speed reasons.

Note notmuch_thread_get_matched_messages now returns the number of
non-excluded matching messages. This API is not totally desirable but
fixing it means breaking binary compatibility so we delay that.

lib/notmuch-private.h
lib/notmuch.h
lib/query.cc
lib/thread.cc

index e791bb0201be592b8763c1f81c8966e78ac33d3f..ea836f721291c3d7d84bfb9edb3f70b3ea717155 100644 (file)
@@ -148,6 +148,8 @@ typedef enum _notmuch_private_status {
 
 typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;
 
+typedef struct _notmuch_string_list notmuch_string_list_t;
+
 /* database.cc */
 
 /* Lookup a prefix value by name.
@@ -216,6 +218,7 @@ _notmuch_thread_create (void *ctx,
                        notmuch_database_t *notmuch,
                        unsigned int seed_doc_id,
                        notmuch_doc_id_set_t *match_set,
+                       notmuch_string_list_t *excluded_terms,
                        notmuch_sort_t sort);
 
 /* message.cc */
@@ -459,11 +462,11 @@ typedef struct _notmuch_string_node {
     struct _notmuch_string_node *next;
 } notmuch_string_node_t;
 
-typedef struct visible _notmuch_string_list {
+struct visible _notmuch_string_list {
     int length;
     notmuch_string_node_t *head;
     notmuch_string_node_t **tail;
-} notmuch_string_list_t;
+};
 
 notmuch_string_list_t *
 _notmuch_string_list_create (const void *ctx);
index f75afaeb1dd0472bc11df31c7f33dcfff3ac687c..babd2086faf4cdaca964dc11638128542b8504d9 100644 (file)
@@ -672,8 +672,10 @@ notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread);
 /* Get the number of messages in 'thread' that matched the search.
  *
  * This count includes only the messages in this thread that were
- * matched by the search from which the thread was created. Contrast
- * with notmuch_thread_get_total_messages() .
+ * matched by the search from which the thread was created and were
+ * not excluded by any exclude tags passed in with the query (see
+ * notmuch_query_add_tag_exclude). Contrast with
+ * notmuch_thread_get_total_messages() .
  */
 int
 notmuch_thread_get_matched_messages (notmuch_thread_t *thread);
index ef2a11f86cf3aa8489bfe1a5bded71fa64249cc3..ab18fbc6124d1c573741a9ebc7ac2dbb77b65086 100644 (file)
@@ -475,6 +475,7 @@ notmuch_threads_get (notmuch_threads_t *threads)
                                   threads->query->notmuch,
                                   doc_id,
                                   &threads->match_set,
+                                  threads->query->exclude_terms,
                                   threads->query->sort);
 }
 
index 0435ee6d1f3a62d24098b8f100bd6356ec2562ea..e976d643db3584f7ce057a7e20dc4adca2bcbdb7 100644 (file)
@@ -214,7 +214,8 @@ _thread_cleanup_author (notmuch_thread_t *thread,
  */
 static void
 _thread_add_message (notmuch_thread_t *thread,
-                    notmuch_message_t *message)
+                    notmuch_message_t *message,
+                    notmuch_string_list_t *exclude_terms)
 {
     notmuch_tags_t *tags;
     const char *tag;
@@ -262,6 +263,15 @@ _thread_add_message (notmuch_thread_t *thread,
         notmuch_tags_move_to_next (tags))
     {
        tag = notmuch_tags_get (tags);
+       /* Mark excluded messages. */
+       for (notmuch_string_node_t *term = exclude_terms->head; term;
+            term = term->next) {
+           /* We ignore initial 'K'. */
+           if (strcmp(tag, (term->string + 1)) == 0) {
+               notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);
+               break;
+           }
+       }
        g_hash_table_insert (thread->tags, xstrdup (tag), NULL);
     }
 }
@@ -321,7 +331,8 @@ _thread_add_matched_message (notmuch_thread_t *thread,
            _thread_set_subject_from_message (thread, message);
     }
 
-    thread->matched_messages++;
+    if (!notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED))
+       thread->matched_messages++;
 
     if (g_hash_table_lookup_extended (thread->message_hash,
                            notmuch_message_get_message_id (message), NULL,
@@ -392,6 +403,7 @@ _notmuch_thread_create (void *ctx,
                        notmuch_database_t *notmuch,
                        unsigned int seed_doc_id,
                        notmuch_doc_id_set_t *match_set,
+                       notmuch_string_list_t *exclude_terms,
                        notmuch_sort_t sort)
 {
     notmuch_thread_t *thread;
@@ -467,7 +479,7 @@ _notmuch_thread_create (void *ctx,
        if (doc_id == seed_doc_id)
            message = seed_message;
 
-       _thread_add_message (thread, message);
+       _thread_add_message (thread, message, exclude_terms);
 
        if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {
            _notmuch_doc_id_set_remove (match_set, doc_id);