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 215A9431FC3 for ; Tue, 20 Mar 2012 13:12:16 -0700 (PDT) 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 bG0v1JxlnyuF for ; Tue, 20 Mar 2012 13:12:14 -0700 (PDT) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 251F0431FAF for ; Tue, 20 Mar 2012 13:12:09 -0700 (PDT) Received: by wibhn6 with SMTP id hn6so483852wib.2 for ; Tue, 20 Mar 2012 13:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=rR1OelO4n28O8ZniT3jdS1YEJTRztUVQm3KpcBm2Tok=; b=x00ylADwCdt+1fDbqVvXl6HgkAoivqAzol/zIkH/8/UkU/BEMG2CBfvn8xvcsERIHN m2G6cg4KCuRFBF2u14B5rwaqLUN0UDsVPanJvv0Iacdl6D+j+zOCkN4S2QbvozM9mAkb 95BoN1NlN+jj2BXP72e7PYUGcji+bFai/x54uZG+azk9PS2cwNDZJKRw/SrXHYuI2zw3 QV/nvukBjdQsFcEjIucdFZON30S7HkLE5ydQQZuHcbeKOIq6NEcCpbTd7A3CmQIznklK 9Mcci65Oyuaq294Ku5HRqwoUGobNU+Y88gN4d24wWSJt1jNYluQv2Cq/CIPvjIzOIToz Juxw== Received: by 10.180.19.196 with SMTP id h4mr2769699wie.12.1332274326437; Tue, 20 Mar 2012 13:12:06 -0700 (PDT) Received: from localhost (94-192-233-223.zone6.bethere.co.uk. [94.192.233.223]) by mx.google.com with ESMTPS id ff9sm36556794wib.2.2012.03.20.13.12.04 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Mar 2012 13:12:05 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [WIP 1/2] lib: multithread Date: Tue, 20 Mar 2012 20:11:59 +0000 Message-Id: <1332274320-17487-2-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1332274320-17487-1-git-send-email-markwalters1009@gmail.com> References: <1332274320-17487-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: Tue, 20 Mar 2012 20:12:16 -0000 --- lib/notmuch.h | 12 ++++++++++++ lib/query.cc | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index babd208..22dd69e 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -445,6 +445,18 @@ typedef enum { NOTMUCH_SORT_UNSORTED } notmuch_sort_t; +/* Values for notmuch_query_secondary_search_conjunction */ +typedef enum { + NOTMUCH_SECONDARY_SEARCH_NONE, + NOTMUCH_SECONDARY_SEARCH_AND, + NOTMUCH_SECONDARY_SEARCH_AND_NOT +} notmuch_ss_conjunction_t; + +void +notmuch_query_set_secondary_search (notmuch_query_t *query, + const char *secondary_search_terms, + notmuch_ss_conjunction_t conjunction); + /* Return the query_string of this query. See notmuch_query_create. */ const char * notmuch_query_get_query_string (notmuch_query_t *query); diff --git a/lib/query.cc b/lib/query.cc index 68ac1e4..0faef51 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -26,6 +26,8 @@ struct _notmuch_query { notmuch_database_t *notmuch; const char *query_string; + const char *secondary_search_terms; + notmuch_ss_conjunction_t ss_conjunction; notmuch_sort_t sort; notmuch_string_list_t *exclude_terms; notmuch_bool_t omit_excluded_messages; @@ -92,6 +94,8 @@ notmuch_query_create (notmuch_database_t *notmuch, query->exclude_terms = _notmuch_string_list_create (query); + query->secondary_search_terms = NULL; + query->omit_excluded_messages = FALSE; return query; @@ -122,6 +126,15 @@ notmuch_query_get_sort (notmuch_query_t *query) } void +notmuch_query_set_secondary_search (notmuch_query_t *query, + const char *secondary_search_terms, + notmuch_ss_conjunction_t conjunction) +{ + query->secondary_search_terms = talloc_strdup (query, secondary_search_terms); + query->ss_conjunction = conjunction; +} + +void notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag) { char *term = talloc_asprintf (query, "%s%s", _find_prefix ("tag"), tag); @@ -454,6 +467,36 @@ notmuch_query_destroy (notmuch_query_t *query) talloc_free (query); } +/* This function tests whether the thread containing document with id + * seed_doc_id satisfies the secondary search terms of query.*/ +notmuch_bool_t +notmuch_thread_test_secondary_search (notmuch_query_t *query, unsigned int seed_doc_id) +{ + int count; + notmuch_message_t *seed_message; + const char *thread_id; + char *thread_id_query_string; + notmuch_query_t *thread_id_query; + + if (!query->secondary_search_terms) return TRUE; + seed_message = _notmuch_message_create (query, query->notmuch, seed_doc_id, NULL); + + thread_id = notmuch_message_get_thread_id (seed_message); + thread_id_query_string = talloc_asprintf (query, "thread:%s and %s", + thread_id, + query->secondary_search_terms); + thread_id_query = notmuch_query_create (query->notmuch, thread_id_query_string); + count = notmuch_query_count_messages (thread_id_query); + switch (query->ss_conjunction) { + case NOTMUCH_SECONDARY_SEARCH_AND: + return (count > 0); + case NOTMUCH_SECONDARY_SEARCH_AND_NOT: + return (count == 0); + default: + return TRUE; + } +} + notmuch_bool_t notmuch_threads_valid (notmuch_threads_t *threads) { @@ -462,7 +505,8 @@ notmuch_threads_valid (notmuch_threads_t *threads) while (threads->doc_id_pos < threads->doc_ids->len) { doc_id = g_array_index (threads->doc_ids, unsigned int, threads->doc_id_pos); - if (_notmuch_doc_id_set_contains (&threads->match_set, doc_id)) + if (_notmuch_doc_id_set_contains (&threads->match_set, doc_id) && + notmuch_thread_test_secondary_search (threads->query, doc_id)) break; threads->doc_id_pos++; -- 1.7.9.1