1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 1B09C429E26
\r
6 for <notmuch@notmuchmail.org>; Sun, 9 Mar 2014 14:41:10 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id 0P38PUJ9FqON for <notmuch@notmuchmail.org>;
\r
17 Sun, 9 Mar 2014 14:41:03 -0700 (PDT)
\r
18 Received: from mail-la0-f43.google.com (mail-la0-f43.google.com
\r
19 [209.85.215.43]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 648A2431FCB
\r
22 for <notmuch@notmuchmail.org>; Sun, 9 Mar 2014 14:40:49 -0700 (PDT)
\r
23 Received: by mail-la0-f43.google.com with SMTP id e16so4196121lan.30
\r
24 for <notmuch@notmuchmail.org>; Sun, 09 Mar 2014 14:40:47 -0700 (PDT)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=1e100.net; s=20130820;
\r
27 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
\r
28 :references:in-reply-to:references;
\r
29 bh=PK2nnlWXwuGi6eczimmyqaHlzZevM7Pxi8TTxhCNny8=;
\r
30 b=c0JgRYlT7IkAaYGhmEnLHcDnFhAQLmNe7GLajCYIFHgvmnWPJKNqE9Lu7HrJwaNaBB
\r
31 CXnzhYbBxNXD3Ihpg0XvdopPnntiOUyLombXkO1KispyoTABrIxYQchPQbqrGaurZjIl
\r
32 fVFeZ5fpGv955ywdymUn8W/ERsXPDfSqlOP5oCCNn7rF9M1sGUqGGcdPCOvdtUtkONXP
\r
33 uVyRPPRiF5aNvIbDu4mDRonXF9UtooDPvOwLbLRsqLfQbNt5GF7ztwNpgoNMrqaW4+wy
\r
34 4xj+F783OBtViNsfGLisS2xEilDcFJU0iyQqRnDHJGNEDiI1kTTBxqWQ4PfrQ74LVmw3
\r
37 ALoCoQmTp4DX3P162u8Z8nXvvZwbORjgDBpC/Z/kwQTyK+oZ5cQ+Q4SqU2RQ0UMaaOCXhat/eblI
\r
38 X-Received: by 10.152.1.199 with SMTP id 7mr21284840lao.24.1394401247515;
\r
39 Sun, 09 Mar 2014 14:40:47 -0700 (PDT)
\r
40 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.
\r
42 by mx.google.com with ESMTPSA id zf7sm26896509lab.7.2014.03.09.14.40.46
\r
43 for <multiple recipients>
\r
44 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
45 Sun, 09 Mar 2014 14:40:46 -0700 (PDT)
\r
46 From: Jani Nikula <jani@nikula.org>
\r
47 To: notmuch@notmuchmail.org
\r
48 Subject: [PATCH v4 04/13] lib: add support for path: prefix searches
\r
49 Date: Sun, 9 Mar 2014 23:40:25 +0200
\r
51 <2a63892eb579cf0cd62a34f6897a2b12d552b617.1394400503.git.jani@nikula.org>
\r
52 X-Mailer: git-send-email 1.9.0
\r
53 In-Reply-To: <cover.1394400503.git.jani@nikula.org>
\r
54 References: <cover.1394400503.git.jani@nikula.org>
\r
55 In-Reply-To: <cover.1394400503.git.jani@nikula.org>
\r
56 References: <cover.1394400503.git.jani@nikula.org>
\r
57 X-BeenThere: notmuch@notmuchmail.org
\r
58 X-Mailman-Version: 2.1.13
\r
60 List-Id: "Use and development of the notmuch mail system."
\r
61 <notmuch.notmuchmail.org>
\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
63 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
65 List-Post: <mailto:notmuch@notmuchmail.org>
\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
68 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
69 X-List-Received-Date: Sun, 09 Mar 2014 21:41:10 -0000
\r
71 The path: prefix is a literal boolean prefix matching the paths,
\r
72 relative from the maildir root, of the message files.
\r
74 path:foo matches all message files in foo (but not in foo/new or
\r
77 path:foo/new matches all message files in foo/new.
\r
79 path:"" matches all message files in the top level maildir.
\r
81 path:foo/** matches all message files in foo and recursively in all
\r
82 subdirectories of foo.
\r
84 path:** matches all message files recursively, i.e. all messages.
\r
86 lib/database.cc | 7 ++++---
\r
87 lib/message.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
\r
88 2 files changed, 49 insertions(+), 10 deletions(-)
\r
90 diff --git a/lib/database.cc b/lib/database.cc
\r
91 index f395061e3a73..93cc7f57e9db 100644
\r
92 --- a/lib/database.cc
\r
93 +++ b/lib/database.cc
\r
94 @@ -100,8 +100,8 @@ typedef struct {
\r
95 * In addition, terms from the content of the message are added with
\r
96 * "from", "to", "attachment", and "subject" prefixes for use by the
\r
97 * user in searching. Similarly, terms from the path of the mail
\r
98 - * message are added with a "folder" prefix. But the database doesn't
\r
99 - * really care itself about any of these.
\r
100 + * message are added with "folder" and "path" prefixes. But the
\r
101 + * database doesn't really care itself about any of these.
\r
103 * The data portion of a mail document is empty.
\r
105 @@ -208,7 +208,8 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
\r
114 static prefix_t PROBABILISTIC_PREFIX[]= {
\r
115 diff --git a/lib/message.cc b/lib/message.cc
\r
116 index 7aff4ae5111a..21abe8e12b9d 100644
\r
117 --- a/lib/message.cc
\r
118 +++ b/lib/message.cc
\r
119 @@ -504,6 +504,40 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)
\r
123 +#define RECURSIVE_SUFFIX "/**"
\r
125 +/* Add "path:" terms for directory. */
\r
126 +static notmuch_status_t
\r
127 +_notmuch_message_add_path_terms (notmuch_message_t *message,
\r
128 + const char *directory)
\r
130 + /* Add exact "path:" term. */
\r
131 + _notmuch_message_add_term (message, "path", directory);
\r
133 + if (strlen (directory)) {
\r
136 + path = talloc_asprintf (NULL, "%s%s", directory, RECURSIVE_SUFFIX);
\r
138 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
140 + /* Add recursive "path:" terms for directory and all parents. */
\r
141 + for (p = path + strlen (path) - 1; p > path; p--) {
\r
143 + strcpy (p, RECURSIVE_SUFFIX);
\r
144 + _notmuch_message_add_term (message, "path", path);
\r
148 + talloc_free (path);
\r
151 + /* Recursive all-matching path:** for consistency. */
\r
152 + _notmuch_message_add_term (message, "path", "**");
\r
154 + return NOTMUCH_STATUS_SUCCESS;
\r
157 /* Add directory based terms for all filenames of the message. */
\r
158 static notmuch_status_t
\r
159 _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)
\r
160 @@ -538,6 +572,8 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)
\r
162 if (strlen (directory))
\r
163 _notmuch_message_gen_terms (message, "folder", directory);
\r
165 + _notmuch_message_add_path_terms (message, directory);
\r
169 @@ -577,6 +613,8 @@ _notmuch_message_add_filename (notmuch_message_t *message,
\r
170 /* New terms allow user to search with folder: specification. */
\r
171 _notmuch_message_gen_terms (message, "folder", directory);
\r
173 + _notmuch_message_add_path_terms (message, directory);
\r
175 talloc_free (local);
\r
177 return NOTMUCH_STATUS_SUCCESS;
\r
178 @@ -618,18 +656,18 @@ _notmuch_message_remove_filename (notmuch_message_t *message,
\r
182 - /* Re-synchronize "folder:" terms for this message. This requires:
\r
183 - * 1. removing all "folder:" terms
\r
184 - * 2. removing all "folder:" stemmed terms
\r
185 - * 3. adding back terms for all remaining filenames of the message. */
\r
186 + /* Re-synchronize "folder:" and "path:" terms for this message. */
\r
188 - /* 1. removing all "folder:" terms */
\r
189 + /* Remove all "folder:" terms. */
\r
190 _notmuch_message_remove_terms (message, folder_prefix);
\r
192 - /* 2. removing all "folder:" stemmed terms */
\r
193 + /* Remove all "folder:" stemmed terms. */
\r
194 _notmuch_message_remove_terms (message, zfolder_prefix);
\r
196 - /* 3. adding back terms for all remaining filenames of the message. */
\r
197 + /* Remove all "path:" terms. */
\r
198 + _notmuch_message_remove_terms (message, _find_prefix ("path"));
\r
200 + /* Add back terms for all remaining filenames of the message. */
\r
201 status = _notmuch_message_add_directory_terms (local, message);
\r
203 talloc_free (local);
\r