unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Al Haji-Ali <abdo.haji.ali@gmail.com>
To: NeilBrown <neilb@suse.de>, "David Bremner" <david@tethera.net>
Cc: notmuch@notmuchmail.org
Subject: Re: notmuch search for threads vs matched messages
Date: Wed, 03 May 2023 17:24:30 +0100	[thread overview]
Message-ID: <m0354dl6wx.fsf@gmail.com> (raw)
In-Reply-To: <168309523277.19756.1509835177569048731@noble.neil.brown.name>

[-- Attachment #1: Type: text/plain, Size: 364 bytes --]


> I would find this helpful too.

I just implemented this for tags (patch attached). Turns out it is not needed for authors as notmuch already distinguishes between matched and unmatched authors -- I never noticed!.

The implementation could of course be debated and improved, but I just wanted to confirm if it is possible to do in theory.

Best regards,
-- Al


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: notmuch-tags.patch --]
[-- Type: text/x-patch, Size: 3405 bytes --]

diff --git a/lib/notmuch.h b/lib/notmuch.h
index 76156178..af0df252 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1498,7 +1498,7 @@ notmuch_thread_get_newest_date (notmuch_thread_t *thread);
  * it if the message is about to be destroyed).
  */
 notmuch_tags_t *
-notmuch_thread_get_tags (notmuch_thread_t *thread);
+notmuch_thread_get_tags (notmuch_thread_t *thread, notmuch_bool_t matched);
 
 /**
  * Destroy a notmuch_thread_t object.
diff --git a/lib/thread.cc b/lib/thread.cc
index 60e9a666..949a91e3 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -41,6 +41,7 @@ struct _notmuch_thread {
     GPtrArray *matched_authors_array;
     char *authors;
     GHashTable *tags;
+    GHashTable *matched_tags;
 
     /* All messages, oldest first. */
     notmuch_message_list_t *message_list;
@@ -61,6 +62,7 @@ _notmuch_thread_destructor (notmuch_thread_t *thread)
     g_hash_table_unref (thread->authors_hash);
     g_hash_table_unref (thread->matched_authors_hash);
     g_hash_table_unref (thread->tags);
+    g_hash_table_unref (thread->matched_tags);
     g_hash_table_unref (thread->message_hash);
 
     if (thread->authors_array) {
@@ -362,6 +364,8 @@ _thread_add_matched_message (notmuch_thread_t *thread,
     time_t date;
     notmuch_message_t *hashed_message;
     notmuch_bool_t is_set;
+    notmuch_tags_t *tags;
+    const char *tag;
 
     date = notmuch_message_get_date (message);
 
@@ -390,6 +394,13 @@ _thread_add_matched_message (notmuch_thread_t *thread,
 				  NOTMUCH_MESSAGE_FLAG_MATCH, 1);
     }
 
+    for (tags = notmuch_message_get_tags (message);
+	 notmuch_tags_valid (tags);
+	 notmuch_tags_move_to_next (tags)) {
+	tag = notmuch_tags_get (tags);
+	g_hash_table_insert (thread->matched_tags, xstrdup (tag), NULL);
+    }
+
     _thread_add_matched_author (thread, _notmuch_message_get_author (hashed_message));
     return 0;
 }
@@ -590,6 +601,8 @@ _notmuch_thread_create (void *ctx,
     thread->authors = NULL;
     thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,
 					  free, NULL);
+    thread->matched_tags = g_hash_table_new_full (g_str_hash, g_str_equal,
+						  free, NULL);
 
     thread->message_list = _notmuch_message_list_create (thread);
     thread->toplevel_list = _notmuch_message_list_create (thread);
@@ -714,7 +727,7 @@ notmuch_thread_get_newest_date (notmuch_thread_t *thread)
 }
 
 notmuch_tags_t *
-notmuch_thread_get_tags (notmuch_thread_t *thread)
+notmuch_thread_get_tags (notmuch_thread_t *thread, notmuch_bool_t matched)
 {
     notmuch_string_list_t *tags;
     GList *keys, *l;
@@ -723,7 +736,7 @@ notmuch_thread_get_tags (notmuch_thread_t *thread)
     if (unlikely (tags == NULL))
 	return NULL;
 
-    keys = g_hash_table_get_keys (thread->tags);
+    keys = g_hash_table_get_keys (matched ? thread->matched_tags : thread->tags);
 
     for (l = keys; l; l = l->next)
 	_notmuch_string_list_append (tags, (char *) l->data);
diff --git a/notmuch-search.c b/notmuch-search.c
index 327e1445..58a4ea79 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -239,7 +239,7 @@ do_search_threads (search_context_t *ctx)
 	    format->map_key (format, "tags");
 	    format->begin_list (format);
 
-	    for (tags = notmuch_thread_get_tags (thread);
+	    for (tags = notmuch_thread_get_tags (thread, 1);
 		 notmuch_tags_valid (tags);
 		 notmuch_tags_move_to_next (tags)) {
 		const char *tag = notmuch_tags_get (tags);

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



      reply	other threads:[~2023-05-03 16:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02 15:44 notmuch search for threads vs matched messages Al Haji-Ali
2023-05-02 17:38 ` Teemu Likonen
2023-05-03  6:27 ` NeilBrown
2023-05-03 16:24   ` Al Haji-Ali [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m0354dl6wx.fsf@gmail.com \
    --to=abdo.haji.ali@gmail.com \
    --cc=david@tethera.net \
    --cc=neilb@suse.de \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).