From 68f51f8fd19576e58b24b7a55dfd459bf6eed5ee Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Fri, 24 Oct 2014 10:23:53 +0100 Subject: [PATCH] Re: [PATCH v1 1/3] search: Seperately report matching and non-matching authors. --- 2b/86cd8eb8411f1215759f64d49afbe8d2b6113b | 298 ++++++++++++++++++++++ 1 file changed, 298 insertions(+) create mode 100644 2b/86cd8eb8411f1215759f64d49afbe8d2b6113b diff --git a/2b/86cd8eb8411f1215759f64d49afbe8d2b6113b b/2b/86cd8eb8411f1215759f64d49afbe8d2b6113b new file mode 100644 index 000000000..874e78c97 --- /dev/null +++ b/2b/86cd8eb8411f1215759f64d49afbe8d2b6113b @@ -0,0 +1,298 @@ +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 1F78F429E27 + for ; Fri, 24 Oct 2014 02:24:28 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 kvvmoqQOr3gJ for ; + Fri, 24 Oct 2014 02:24:20 -0700 (PDT) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id D0C4D431FD8 + for ; Fri, 24 Oct 2014 02:24:19 -0700 (PDT) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1Xhb6B-00034K-EB; Fri, 24 Oct 2014 10:24:15 +0100 +Received: from 5751dfa2.skybroadband.com ([87.81.223.162] helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71) + (envelope-from ) + id 1Xhb6A-0003ml-Mn; Fri, 24 Oct 2014 10:23:55 +0100 +From: Mark Walters +To: David Edmondson , notmuch@notmuchmail.org +Subject: Re: [PATCH v1 1/3] search: Seperately report matching and + non-matching authors. +In-Reply-To: <1414140488-29978-2-git-send-email-dme@dme.org> +References: <1414140488-29978-1-git-send-email-dme@dme.org> + <1414140488-29978-2-git-send-email-dme@dme.org> +User-Agent: Notmuch/0.18.1+86~gef5e66a (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Fri, 24 Oct 2014 10:23:53 +0100 +Message-ID: <87y4s5vn12.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 87.81.223.162 +X-QM-Geographic: According to ripencc, + this message was delivered by a machine in Britain (UK) (GB). +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: fea76dc32e0ad6a59ad4b1f29aed2695 (of first 20000 bytes) +X-SpamAssassin-Score: -0.1 +X-SpamAssassin-SpamBar: / +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -0.1 points. + Summary of the scoring: + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * -0.1 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +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: Fri, 24 Oct 2014 09:24:28 -0000 + + +Hi + +I definitely like the idea: some comments below. + +On Fri, 24 Oct 2014, David Edmondson wrote: +> In addition to the :authors attribute of each search result, include +> :authors_matched and :authors_non_matched attributes. Both attributes +> are always included. If there are no non-matching authors, the +> :authors_non_matched attribute is set to the empty string. + +What about having both authors_matched and authors_not_matched as lists +of authors (ie one string for each author)? Then emacs, for example, +wouldn't try and parse the string back into authors before +splitting. And authors_non_matched could be an empty list when +appropriate which seems more natural than the empty string. + +All the above is based on what a client might want in the output rather +than what is easy or sensible to implement in the C code. + +> --- +> lib/notmuch.h | 34 ++++++++++++++++++++++++++++++++ +> lib/thread.cc | 60 +++++++++++++++++++++++++++++++++++++++----------------- +> notmuch-search.c | 6 ++++++ +> 3 files changed, 82 insertions(+), 18 deletions(-) +> +> diff --git a/lib/notmuch.h b/lib/notmuch.h +> index dae0416..30ce6c3 100644 +> --- a/lib/notmuch.h +> +++ b/lib/notmuch.h +> @@ -993,6 +993,40 @@ const char * +> notmuch_thread_get_authors (notmuch_thread_t *thread); +> +> /** +> + * Get the matched authors of 'thread' as a UTF-8 string. +> + * +> + * The returned string is a comma-separated list of the names of the +> + * authors of mail messages in the query results that belong to this +> + * thread. +> + * +> + * Authors are ordered by date. +> + * +> + * The returned string belongs to 'thread' and as such, should not be +> + * modified by the caller and will only be valid for as long as the +> + * thread is valid, (which is until notmuch_thread_destroy or until +> + * the query from which it derived is destroyed). +> + */ +> +const char * +> +notmuch_thread_get_authors_matched (notmuch_thread_t *thread); +> + +> +/** +> + * Get the non-matched authors of 'thread' as a UTF-8 string. +> + * +> + * The returned string is a comma-separated list of the names of the +> + * authors of mail messages in the query results that belong to this +> + * thread. +> + * +> + * Authors are ordered by date. +> + * +> + * The returned string belongs to 'thread' and as such, should not be +> + * modified by the caller and will only be valid for as long as the +> + * thread is valid, (which is until notmuch_thread_destroy or until +> + * the query from which it derived is destroyed). +> + */ +> +const char * +> +notmuch_thread_get_authors_non_matched (notmuch_thread_t *thread); +> + +> +/** +> * Get the subject of 'thread' as a UTF-8 string. +> * +> * The subject is taken from the first message (according to the query +> diff --git a/lib/thread.cc b/lib/thread.cc +> index 8922403..b344875 100644 +> --- a/lib/thread.cc +> +++ b/lib/thread.cc +> @@ -33,6 +33,8 @@ struct visible _notmuch_thread { +> GHashTable *matched_authors_hash; +> GPtrArray *matched_authors_array; +> char *authors; +> + char *authors_matched; +> + char *authors_non_matched; +> GHashTable *tags; +> +> /* All messages, oldest first. */ +> @@ -112,10 +114,11 @@ _thread_add_matched_author (notmuch_thread_t *thread, +> g_ptr_array_add (thread->matched_authors_array, author_copy); +> } +> +> -/* Construct an authors string from matched_authors_array and +> - * authors_array. The string contains matched authors first, then +> - * non-matched authors (with the two groups separated by '|'). Within +> - * each group, authors are listed in date order. */ +> +/* Construct the authors_matched, authors_non_matched and authors +> + * strings from matched_authors_array and authors_array. The authors +> + * string contains matched authors first, then non-matched authors +> + * (with the two groups separated by '|'). Within each group, authors +> + * are listed in date order. */ +> static void +> _resolve_thread_authors_string (notmuch_thread_t *thread) +> { +> @@ -123,36 +126,43 @@ _resolve_thread_authors_string (notmuch_thread_t *thread) +> char *author; +> int first_non_matched_author = 1; +> +> - /* First, list all matched authors in date order. */ +> + /* List all matched authors in date order. */ +> for (i = 0; i < thread->matched_authors_array->len; i++) { +> author = (char *) g_ptr_array_index (thread->matched_authors_array, i); +> - if (thread->authors) +> - thread->authors = talloc_asprintf (thread, "%s, %s", +> - thread->authors, +> - author); +> - else +> - thread->authors = author; +> + if (thread->authors_matched) { +> + thread->authors_matched = talloc_asprintf (thread, "%s, %s", +> + thread->authors_matched, +> + author); +> + } else { +> + thread->authors_matched = author; +> + } +> } +> +> - /* Next, append any non-matched authors that haven't already appeared. */ +> + /* List any non-matched authors that haven't already appeared. */ +> for (i = 0; i < thread->authors_array->len; i++) { +> author = (char *) g_ptr_array_index (thread->authors_array, i); +> if (g_hash_table_lookup_extended (thread->matched_authors_hash, +> author, NULL, NULL)) +> continue; +> if (first_non_matched_author) { +> - thread->authors = talloc_asprintf (thread, "%s| %s", +> - thread->authors, +> - author); +> + thread->authors_non_matched = author; +> } else { +> - thread->authors = talloc_asprintf (thread, "%s, %s", +> - thread->authors, +> - author); +> + thread->authors_non_matched = talloc_asprintf (thread, "%s, %s", +> + thread->authors_non_matched, +> + author); +> } +> +> first_non_matched_author = 0; + +I think I would prefer to make this look like the matched case and drop +the first_non_matched_author stuff. + +Best wishes + +Mark + +> } +> +> + /* List both matched and any non-matched authors. */ +> + if (thread->authors_non_matched) +> + thread->authors = talloc_asprintf (thread, "%s| %s", +> + thread->authors_matched, +> + thread->authors_non_matched); +> + else +> + thread->authors = thread->authors_matched; +> + +> g_ptr_array_free (thread->authors_array, TRUE); +> thread->authors_array = NULL; +> g_ptr_array_free (thread->matched_authors_array, TRUE); +> @@ -473,6 +483,8 @@ _notmuch_thread_create (void *ctx, +> NULL, NULL); +> thread->matched_authors_array = g_ptr_array_new (); +> thread->authors = NULL; +> + thread->authors_matched = NULL; +> + thread->authors_non_matched = NULL; +> thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal, +> free, NULL); +> +> @@ -568,6 +580,18 @@ notmuch_thread_get_authors (notmuch_thread_t *thread) +> } +> +> const char * +> +notmuch_thread_get_authors_matched (notmuch_thread_t *thread) +> +{ +> + return thread->authors_matched; +> +} +> + +> +const char * +> +notmuch_thread_get_authors_non_matched (notmuch_thread_t *thread) +> +{ +> + return thread->authors_non_matched; +> +} +> + +> +const char * +> notmuch_thread_get_subject (notmuch_thread_t *thread) +> { +> return thread->subject; +> diff --git a/notmuch-search.c b/notmuch-search.c +> index bc9be45..f1b096d 100644 +> --- a/notmuch-search.c +> +++ b/notmuch-search.c +> @@ -114,6 +114,8 @@ do_search_threads (sprinter_t *format, +> } else { /* output == OUTPUT_SUMMARY */ +> void *ctx_quote = talloc_new (thread); +> const char *authors = notmuch_thread_get_authors (thread); +> + const char *authors_matched = notmuch_thread_get_authors_matched (thread); +> + const char *authors_non_matched = notmuch_thread_get_authors_non_matched (thread); +> const char *subject = notmuch_thread_get_subject (thread); +> const char *thread_id = notmuch_thread_get_thread_id (thread); +> int matched = notmuch_thread_get_matched_messages (thread); +> @@ -152,6 +154,10 @@ do_search_threads (sprinter_t *format, +> format->integer (format, total); +> format->map_key (format, "authors"); +> format->string (format, authors); +> + format->map_key (format, "authors_matched"); +> + format->string (format, authors_matched); +> + format->map_key (format, "authors_non_matched"); +> + format->string (format, authors_non_matched); +> format->map_key (format, "subject"); +> format->string (format, subject); +> if (notmuch_format_version >= 2) { +> -- +> 2.1.1 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2