From: Jani Nikula Date: Sat, 22 Feb 2014 22:25:33 +0000 (+0200) Subject: [PATCH v2 02/13] lib: add support for path: prefix searches X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=772333747b61d098467fc2d867e5e886e197583a;p=notmuch-archives.git [PATCH v2 02/13] lib: add support for path: prefix searches --- diff --git a/79/a3bf76d10de0ff5ffb1f45aeb41468a19987f4 b/79/a3bf76d10de0ff5ffb1f45aeb41468a19987f4 new file mode 100644 index 000000000..666c43e10 --- /dev/null +++ b/79/a3bf76d10de0ff5ffb1f45aeb41468a19987f4 @@ -0,0 +1,205 @@ +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 89274431FD9 + for ; Sat, 22 Feb 2014 14:26:01 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 dnqFO705w1Nj for ; + Sat, 22 Feb 2014 14:25:53 -0800 (PST) +Received: from mail-ea0-f169.google.com (mail-ea0-f169.google.com + [209.85.215.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 241F0431FC3 + for ; Sat, 22 Feb 2014 14:25:53 -0800 (PST) +Received: by mail-ea0-f169.google.com with SMTP id d10so1086991eaj.14 + for ; Sat, 22 Feb 2014 14:25:51 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=vqdBISaLpPXaqODOUueqCCfr2FgpsZCLiz0uTMGL7Nc=; + b=NlE5iKvplI41WZCoUbnw84//DxfGqOFNQHitjH+CgOkkzkFG8OiiIdAtHkuDze4Pg0 + YUtMKKoyDbpb3nIyC/pc+d00WBNZttVQZD6stgTbtkEd/fYygmLqrusBANgdcroNIPik + AOHSQ2z22PJvn1EkVyD9VFCW+Buflfd1pwCMO9/G45W3m4szr+Sq2Lh/VxmL58XZSXFR + UnAJ1yrgpwqjtO6P9Mue35OMSzrBxyFrJyWDXqBxvEdx5yjJaRwQCwsVpLtfLyxHuaCj + YI1w/cZaz/O5POrbt4XX9d//soLOBS9BkEz9C96U4qay1IQka6Tks6CC8hjfcYRzMPkj + +b6A== +X-Gm-Message-State: + ALoCoQljb1ZXzZcYXy0dNHDSV6+IgWiCw2PddKp7cyP1tKU/VbZAxoqqQQ6prNi9c3lI9eC1+xDw +X-Received: by 10.14.104.6 with SMTP id h6mr16364290eeg.29.1393107951896; + Sat, 22 Feb 2014 14:25:51 -0800 (PST) +Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. + [88.195.111.91]) by mx.google.com with ESMTPSA id + k41sm43758692een.19.2014.02.22.14.25.50 for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sat, 22 Feb 2014 14:25:51 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v2 02/13] lib: add support for path: prefix searches +Date: Sun, 23 Feb 2014 00:25:33 +0200 +Message-Id: + <409b48d482efd16282f696ef6e7e5053b5aa5b82.1393105055.git.jani@nikula.org> +X-Mailer: git-send-email 1.8.5.3 +In-Reply-To: +References: +In-Reply-To: +References: +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: Sat, 22 Feb 2014 22:26:01 -0000 + +The path: prefix is a literal boolean prefix matching the paths, +relative from the maildir root, of the message files. + +path:foo matches all message files in foo (but not in foo/new or +foo/cur). + +path:foo/new matches all message files in foo/new. + +path:"" matches all message files in the top level maildir. + +path:foo/** matches all message files in foo and recursively in all +subdirectories of foo. + +path:** matches all message files recursively, i.e. all messages. +--- + lib/database.cc | 7 ++++--- + lib/message.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++------- + 2 files changed, 49 insertions(+), 10 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index f395061e3a73..93cc7f57e9db 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -100,8 +100,8 @@ typedef struct { + * In addition, terms from the content of the message are added with + * "from", "to", "attachment", and "subject" prefixes for use by the + * user in searching. Similarly, terms from the path of the mail +- * message are added with a "folder" prefix. But the database doesn't +- * really care itself about any of these. ++ * message are added with "folder" and "path" prefixes. But the ++ * database doesn't really care itself about any of these. + * + * The data portion of a mail document is empty. + * +@@ -208,7 +208,8 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = { + { "thread", "G" }, + { "tag", "K" }, + { "is", "K" }, +- { "id", "Q" } ++ { "id", "Q" }, ++ { "path", "P" }, + }; + + static prefix_t PROBABILISTIC_PREFIX[]= { +diff --git a/lib/message.cc b/lib/message.cc +index 7aff4ae5111a..21abe8e12b9d 100644 +--- a/lib/message.cc ++++ b/lib/message.cc +@@ -504,6 +504,40 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix) + } + } + ++#define RECURSIVE_SUFFIX "/**" ++ ++/* Add "path:" terms for directory. */ ++static notmuch_status_t ++_notmuch_message_add_path_terms (notmuch_message_t *message, ++ const char *directory) ++{ ++ /* Add exact "path:" term. */ ++ _notmuch_message_add_term (message, "path", directory); ++ ++ if (strlen (directory)) { ++ char *path, *p; ++ ++ path = talloc_asprintf (NULL, "%s%s", directory, RECURSIVE_SUFFIX); ++ if (! path) ++ return NOTMUCH_STATUS_OUT_OF_MEMORY; ++ ++ /* Add recursive "path:" terms for directory and all parents. */ ++ for (p = path + strlen (path) - 1; p > path; p--) { ++ if (*p == '/') { ++ strcpy (p, RECURSIVE_SUFFIX); ++ _notmuch_message_add_term (message, "path", path); ++ } ++ } ++ ++ talloc_free (path); ++ } ++ ++ /* Recursive all-matching path:** for consistency. */ ++ _notmuch_message_add_term (message, "path", "**"); ++ ++ return NOTMUCH_STATUS_SUCCESS; ++} ++ + /* Add directory based terms for all filenames of the message. */ + static notmuch_status_t + _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message) +@@ -538,6 +572,8 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message) + directory_id); + if (strlen (directory)) + _notmuch_message_gen_terms (message, "folder", directory); ++ ++ _notmuch_message_add_path_terms (message, directory); + } + + return status; +@@ -577,6 +613,8 @@ _notmuch_message_add_filename (notmuch_message_t *message, + /* New terms allow user to search with folder: specification. */ + _notmuch_message_gen_terms (message, "folder", directory); + ++ _notmuch_message_add_path_terms (message, directory); ++ + talloc_free (local); + + return NOTMUCH_STATUS_SUCCESS; +@@ -618,18 +656,18 @@ _notmuch_message_remove_filename (notmuch_message_t *message, + if (status) + return status; + +- /* Re-synchronize "folder:" terms for this message. This requires: +- * 1. removing all "folder:" terms +- * 2. removing all "folder:" stemmed terms +- * 3. adding back terms for all remaining filenames of the message. */ ++ /* Re-synchronize "folder:" and "path:" terms for this message. */ + +- /* 1. removing all "folder:" terms */ ++ /* Remove all "folder:" terms. */ + _notmuch_message_remove_terms (message, folder_prefix); + +- /* 2. removing all "folder:" stemmed terms */ ++ /* Remove all "folder:" stemmed terms. */ + _notmuch_message_remove_terms (message, zfolder_prefix); + +- /* 3. adding back terms for all remaining filenames of the message. */ ++ /* Remove all "path:" terms. */ ++ _notmuch_message_remove_terms (message, _find_prefix ("path")); ++ ++ /* Add back terms for all remaining filenames of the message. */ + status = _notmuch_message_add_directory_terms (local, message); + + talloc_free (local); +-- +1.8.5.3 +