Re: storing From and Subject in xapian
authorIstvan Marko <notmuch@kismala.com>
Mon, 16 May 2011 07:33:29 +0000 (00:33 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:38:15 +0000 (09:38 -0800)
f3/493b146c1dea8ed6a82f3fcdf84f08b3f984cd [new file with mode: 0644]

diff --git a/f3/493b146c1dea8ed6a82f3fcdf84f08b3f984cd b/f3/493b146c1dea8ed6a82f3fcdf84f08b3f984cd
new file mode 100644 (file)
index 0000000..7dc8fc3
--- /dev/null
@@ -0,0 +1,188 @@
+Return-Path: <mi@kismala.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1AD7C431FD0\r
+       for <notmuch@notmuchmail.org>; Mon, 16 May 2011 00:33:39 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id XPi-WwaB0Jpg for <notmuch@notmuchmail.org>;\r
+       Mon, 16 May 2011 00:33:36 -0700 (PDT)\r
+Received: from imarko.xen.prgmr.com (imarko.xen.prgmr.com [72.13.95.244])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 16857431FB6\r
+       for <notmuch@notmuchmail.org>; Mon, 16 May 2011 00:33:36 -0700 (PDT)\r
+Received: from localhost ([127.0.0.1] helo=zsu.kismala.com)\r
+       by imarko.xen.prgmr.com with esmtp (Exim 4.75)\r
+       (envelope-from <mi@kismala.com>)\r
+       id 1QLsIz-0004PY-Nr; Mon, 16 May 2011 00:33:29 -0700\r
+From: Istvan Marko <notmuch@kismala.com>\r
+To: Austin Clements <amdragon@mit.edu>\r
+Subject: Re: storing From and Subject in xapian\r
+References: <m3sjsv2kw2.fsf@zsu.kismala.com>\r
+       <BANLkTinVzQL2qRDbt4WhcPdL1D7D3N=aQg@mail.gmail.com>\r
+Date: Mon, 16 May 2011 00:33:29 -0700\r
+In-Reply-To: <BANLkTinVzQL2qRDbt4WhcPdL1D7D3N=aQg@mail.gmail.com> (Austin\r
+       Clements's message of "Sat, 14 May 2011 21:37:25 -0400")\r
+Message-ID: <m3pqnj2j7a.fsf@zsu.kismala.com>\r
+User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)\r
+MIME-Version: 1.0\r
+Content-Type: multipart/mixed; boundary="=-=-="\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 16 May 2011 07:33:39 -0000\r
+\r
+--=-=-=\r
+Content-Type: text/plain\r
+\r
+Austin Clements <amdragon@mit.edu> writes:\r
+\r
+> I wonder if a better approach would be to use\r
+> notmuch_message_get_header everywhere, rather than introducing\r
+> _notmuch_message_get_header_value, and have it simply recognize\r
+> headers that can be retrieved directly from the database.  Then\r
+> library callers could take advantage of this optimization and it could\r
+> be trivially extended to other headers in the future.\r
+\r
+That's a good idea, updated patch below. This version also has fallback\r
+handling for database entries that don't have the new header value\r
+fields.\r
+\r
+I couldn't find a way to have the Xapian API differentiate between\r
+undefined and blank value fields so empty subject lines are encoded as a\r
+single space.\r
+\r
+Also, the address completion discussion made me think that maybe a value\r
+field containing To/Cc/Bcc could be added too to avoid message file\r
+parsing for the address search case but I haven't tried implementing\r
+that yet.\r
+\r
+\r
+--=-=-=\r
+Content-Type: text/x-patch\r
+Content-Disposition: inline; filename=notmuch-value3.patch\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 7f8a830..d30c1b0 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1698,7 +1698,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
+               goto DONE;\r
\r
+           date = notmuch_message_file_get_header (message_file, "date");\r
+-          _notmuch_message_set_date (message, date);\r
++          _notmuch_message_set_header_values (message, date, from, subject);\r
\r
+           _notmuch_message_index_file (message, filename);\r
+       } else {\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index e8cf8d9..2a76dc1 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -414,6 +414,27 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)\r
+ const char *\r
+ notmuch_message_get_header (notmuch_message_t *message, const char *header)\r
+ {\r
++    std::string value;\r
++\r
++    // fetch header from the appropriate xapian value field if available\r
++    if (strcmp(header,"from") == 0)\r
++        value=message->doc.get_value(NOTMUCH_VALUE_FROM);\r
++    else if (strcmp(header,"subject") == 0)\r
++        value=message->doc.get_value (NOTMUCH_VALUE_SUBJECT);\r
++    else if (strcmp(header,"message-id") == 0)\r
++      value=message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID);\r
++\r
++    if (!value.empty()) {\r
++      // empty headers are encoded as a single space because xapian\r
++      // doesn't seem to differentiat between unset and empty value\r
++      // fields\r
++      if (value == " ")\r
++          return "";\r
++      else\r
++          return talloc_strdup (message, value.c_str ());\r
++    }\r
++\r
++    // otherwise fall back to parsing the file\r
+     _notmuch_message_ensure_message_file (message);\r
+     if (message->message_file == NULL)\r
+       return NULL;\r
+@@ -771,8 +792,10 @@ notmuch_message_set_author (notmuch_message_t *message,\r
+ }\r
\r
+ void\r
+-_notmuch_message_set_date (notmuch_message_t *message,\r
+-                         const char *date)\r
++_notmuch_message_set_header_values (notmuch_message_t *message,\r
++                                  const char *date,\r
++                                  const char *from,\r
++                                  const char *subject)\r
+ {\r
+     time_t time_value;\r
\r
+@@ -785,6 +808,9 @@ _notmuch_message_set_date (notmuch_message_t *message,\r
\r
+     message->doc.add_value (NOTMUCH_VALUE_TIMESTAMP,\r
+                           Xapian::sortable_serialise (time_value));\r
++    message->doc.add_value (NOTMUCH_VALUE_FROM, from);\r
++    // empty subject is encoded as a single space\r
++    message->doc.add_value (NOTMUCH_VALUE_SUBJECT, (*subject==0) ? " " : subject);\r
+ }\r
\r
+ /* Synchronize changes made to message->doc out into the database. */\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index 0856751..ed3d32d 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -105,7 +105,9 @@ _internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);\r
\r
+ typedef enum {\r
+     NOTMUCH_VALUE_TIMESTAMP = 0,\r
+-    NOTMUCH_VALUE_MESSAGE_ID\r
++    NOTMUCH_VALUE_MESSAGE_ID,\r
++    NOTMUCH_VALUE_FROM,\r
++    NOTMUCH_VALUE_SUBJECT\r
+ } notmuch_value_t;\r
\r
+ /* Xapian (with flint backend) complains if we provide a term longer\r
+@@ -281,9 +283,10 @@ void\r
+ _notmuch_message_ensure_thread_id (notmuch_message_t *message);\r
\r
+ void\r
+-_notmuch_message_set_date (notmuch_message_t *message,\r
+-                         const char *date);\r
+-\r
++_notmuch_message_set_header_values (notmuch_message_t *message,\r
++                                  const char *date,\r
++                                  const char *from,\r
++                                  const char *subject);\r
+ void\r
+ _notmuch_message_sync (notmuch_message_t *message);\r
\r
+\r
+--=-=-=\r
+Content-Type: text/plain\r
+\r
+\r
+-- \r
+       Istvan\r
+\r
+--=-=-=--\r