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