From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 1EB2A6DE1C6F for ; Sun, 26 Feb 2017 18:34:31 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aL2-7nWMuGvh for ; Sun, 26 Feb 2017 18:34:30 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 3C71F6DE1C6C for ; Sun, 26 Feb 2017 18:34:30 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1ciB8H-000111-Ng for notmuch@notmuchmail.org; Sun, 26 Feb 2017 21:33:49 -0500 Received: (nullmailer pid 27731 invoked by uid 1000); Mon, 27 Feb 2017 02:34:26 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: v6 of regexp searching Date: Sun, 26 Feb 2017 22:34:18 -0400 Message-Id: <20170227023422.26929-1-david@tethera.net> X-Mailer: git-send-email 2.11.0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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, 27 Feb 2017 02:34:31 -0000 This obsoletes the unmerged patches from id:20170217030754.32069-1-david@tethera.net The first two I plan to merge for 0.24 (barring corrections or objections) [PATCH 1/4] lib: create field processors from prefix table [PATCH 2/4] lib: regexp matching in 'subject' and 'from' The second two could go in for 0.24, or wait. [PATCH 3/4] lib: add mid: as a synonym for id: [PATCH 4/4] lib: Add regexp searching for mid: prefix The big change is a fix for the problem Jani noticed in id:87innwhhid.fsf@nikula.org in the case where field processors are not present. Interdiff follows. diff --git a/lib/database-private.h b/lib/database-private.h index 9fd4102c..ab3d9691 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -154,7 +154,7 @@ typedef enum notmuch_field_flags { NOTMUCH_FIELD_NO_FLAGS = 0, NOTMUCH_FIELD_EXTERNAL = 1 << 0, NOTMUCH_FIELD_PROBABILISTIC = 1 << 1, - NOTMUCH_FIELD_PROCESSOR = 1 << 2 + NOTMUCH_FIELD_PROCESSOR = 1 << 2, } notmuch_field_flag_t; /* diff --git a/lib/database.cc b/lib/database.cc index 6e5ea106..09337602 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -293,19 +293,42 @@ prefix_t prefix_table[] = { NOTMUCH_FIELD_PROCESSOR}, }; +static void +_setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch) +{ + if (prefix->flags & NOTMUCH_FIELD_PROBABILISTIC) + notmuch->query_parser->add_prefix (prefix->name, prefix->prefix); + else + notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix); +} + #if HAVE_XAPIAN_FIELD_PROCESSOR -static Xapian::FieldProcessor * -_make_field_processor (const char *name, notmuch_field_flag_t options, - notmuch_database_t *notmuch) { - if (STRNCMP_LITERAL (name, "date") == 0) - return (new DateFieldProcessor())->release (); - else if (STRNCMP_LITERAL(name, "query") == 0) - return (new QueryFieldProcessor (*notmuch->query_parser, notmuch))->release (); +static void +_setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) +{ + if (prefix->flags & NOTMUCH_FIELD_PROCESSOR) { + Xapian::FieldProcessor *fp; + + if (STRNCMP_LITERAL (prefix->name, "date") == 0) + fp = (new DateFieldProcessor())->release (); + else if (STRNCMP_LITERAL(prefix->name, "query") == 0) + fp = (new QueryFieldProcessor (*notmuch->query_parser, notmuch))->release (); else - return (new RegexpFieldProcessor (name, options, *notmuch->query_parser, notmuch))->release (); + fp = (new RegexpFieldProcessor (prefix->name, prefix->flags, + *notmuch->query_parser, notmuch))->release (); + + /* we treat all field-processor fields as boolean in order to get the raw input */ + notmuch->query_parser->add_boolean_prefix (prefix->name, fp); + } else { + _setup_query_field_default (prefix, notmuch); + } } #else -#define _make_field_processor(name, options, db) NULL +static inline void +_setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) +{ + _setup_query_field_default (prefix, notmuch); +} #endif const char * @@ -1067,22 +1090,7 @@ notmuch_database_open_verbose (const char *path, for (i = 0; i < ARRAY_SIZE (prefix_table); i++) { const prefix_t *prefix = &prefix_table[i]; if (prefix->flags & NOTMUCH_FIELD_EXTERNAL) { - /* we treat all field-processor fields as boolean in order - to get the raw input */ - if (HAVE_XAPIAN_FIELD_PROCESSOR && - (prefix->flags & NOTMUCH_FIELD_PROCESSOR)) { - Xapian::FieldProcessor *fp = _make_field_processor (prefix->name, - prefix->flags, - notmuch); - - notmuch->query_parser->add_boolean_prefix (prefix->name, fp); - } else if (prefix->flags & NOTMUCH_FIELD_PROBABILISTIC) { - notmuch->query_parser->add_prefix (prefix->name, - prefix->prefix); - } else { - notmuch->query_parser->add_boolean_prefix (prefix->name, - prefix->prefix); - } + _setup_query_field (prefix, notmuch); } } } catch (const Xapian::Error &error) { diff --git a/lib/regexp-fields.h b/lib/regexp-fields.h index 8a0e72e1..72d12b37 100644 --- a/lib/regexp-fields.h +++ b/lib/regexp-fields.h @@ -63,7 +63,7 @@ class RegexpFieldProcessor : public Xapian::FieldProcessor { protected: Xapian::valueno slot; std::string term_prefix; - int options; + notmuch_field_flag_t options; Xapian::QueryParser &parser; notmuch_database_t *notmuch; diff --git a/test/T630-regexp-query.sh b/test/T650-regexp-query.sh similarity index 37% rename from test/T630-regexp-query.sh rename to test/T650-regexp-query.sh index 96bd8746..f0868a15 100755 --- a/test/T630-regexp-query.sh +++ b/test/T650-regexp-query.sh @@ -5,7 +5,9 @@ test_description='regular expression searches' add_email_corpus -if [ $NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR -eq 1 ]; then +if [ $NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR -eq 0 ]; then + test_done +fi notmuch search --output=messages from:cworth > cworth.msg-ids @@ -76,6 +78,21 @@ A Xapian exception occurred performing query: Invalid regular expression Query string was: from:/unbalanced[/ EOF test_expect_equal_file EXPECTED OUTPUT -fi + +test_begin_subtest "empty mid search" +notmuch search --output=messages mid:yoom > OUTPUT +cp /dev/null EXPECTED +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "non-empty mid regex search" +notmuch search --output=messages mid:/yoom/ > OUTPUT +test_expect_equal_file cworth.msg-ids OUTPUT + +test_begin_subtest "combine regexp mid and subject" +notmuch search subject:/-C/ and mid:/y..m/ | notmuch_search_sanitize > OUTPUT +cat < EXPECTED +thread:XXX 2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread) +EOF +test_expect_equal_file EXPECTED OUTPUT test_done