Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id A8B62431FBF for ; Sat, 25 Feb 2012 19:26:01 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id n84t0+KgD835 for ; Sat, 25 Feb 2012 19:26:00 -0800 (PST) Received: from mail-ww0-f41.google.com (mail-ww0-f41.google.com [74.125.82.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 80140431FAE for ; Sat, 25 Feb 2012 19:26:00 -0800 (PST) Received: by wgbds1 with SMTP id ds1so238785wgb.2 for ; Sat, 25 Feb 2012 19:25:59 -0800 (PST) Received-SPF: pass (google.com: domain of markwalters1009@gmail.com designates 10.180.102.132 as permitted sender) client-ip=10.180.102.132; Authentication-Results: mr.google.com; spf=pass (google.com: domain of markwalters1009@gmail.com designates 10.180.102.132 as permitted sender) smtp.mail=markwalters1009@gmail.com; dkim=pass header.i=markwalters1009@gmail.com Received: from mr.google.com ([10.180.102.132]) by 10.180.102.132 with SMTP id fo4mr7814576wib.6.1330226759530 (num_hops = 1); Sat, 25 Feb 2012 19:25:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=BsaS5Zpnoh6DatNKWnhrJrtCDw2ujgE0cyPqM93aJfM=; b=ks77y3BzRfJSIo2cI5QH1IMrKEmQKlrqm4QSmkENfz2c30s5RESjdR9IuD5kpdGioi uEmO8E6wZq/FS4L4AoLlPcsUD0+yH9O9lG+Yge6kRv7Aa1RxCW/ehmk0ahNdsJnvuQd8 m7HKXJ+D8vDKIb045U/pEl/qs9vSI0jhiO5Ek= Received: by 10.180.102.132 with SMTP id fo4mr1766457wib.6.1330157139391; Sat, 25 Feb 2012 00:05:39 -0800 (PST) Received: from localhost (94-192-233-223.zone6.bethere.co.uk. [94.192.233.223]) by mx.google.com with ESMTPS id dr5sm20713170wib.0.2012.02.25.00.05.38 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 25 Feb 2012 00:05:38 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org, Austin Clements Subject: [Patch v6 06/13] lib: Add the exclude flag to notmuch_query_search_threads Date: Sat, 25 Feb 2012 08:06:37 +0000 Message-Id: <1330157204-26094-7-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1330157204-26094-1-git-send-email-markwalters1009@gmail.com> References: <1330157204-26094-1-git-send-email-markwalters1009@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Feb 2012 03:26:04 -0000 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 | 7 +++++-- lib/notmuch.h | 6 ++++-- lib/query.cc | 1 + lib/thread.cc | 18 +++++++++++++++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index e791bb0..ea836f7 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -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); diff --git a/lib/notmuch.h b/lib/notmuch.h index f75afae..babd208 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -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); diff --git a/lib/query.cc b/lib/query.cc index ef2a11f..ab18fbc 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -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); } diff --git a/lib/thread.cc b/lib/thread.cc index 0435ee6..e976d64 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -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); -- 1.7.2.3