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 E53516DE1973 for ; Thu, 16 Feb 2017 19:08:04 -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 pE86wnUkg5c5 for ; Thu, 16 Feb 2017 19:08:03 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id A7DC26DE1966 for ; Thu, 16 Feb 2017 19:08:03 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1ceYtK-00035E-SU; Thu, 16 Feb 2017 22:07:26 -0500 Received: (nullmailer pid 32143 invoked by uid 1000); Fri, 17 Feb 2017 03:07:58 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [patch v5 6/6] lib: Add regexp searching for mid: prefix Date: Thu, 16 Feb 2017 23:07:54 -0400 Message-Id: <20170217030754.32069-7-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170217030754.32069-1-david@tethera.net> References: <20170217030754.32069-1-david@tethera.net> 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: Fri, 17 Feb 2017 03:08:05 -0000 The bulk of the change is passing in the field options to the regexp field processor, so that we can properly handle the fallback (non-regexp case). --- lib/database.cc | 11 +++++++---- lib/regexp-fields.cc | 28 +++++++++++++++++++++------- lib/regexp-fields.h | 4 +++- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 21c8c5f2..5f02d218 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -262,7 +262,8 @@ prefix_t prefix_table[] = { { "tag", "K", NOTMUCH_FIELD_EXTERNAL }, { "is", "K", NOTMUCH_FIELD_EXTERNAL }, { "id", "Q", NOTMUCH_FIELD_EXTERNAL }, - { "mid", "Q", NOTMUCH_FIELD_EXTERNAL }, + { "mid", "Q", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROCESSOR }, { "path", "P", NOTMUCH_FIELD_EXTERNAL }, { "property", "XPROPERTY", NOTMUCH_FIELD_EXTERNAL }, /* @@ -294,16 +295,17 @@ prefix_t prefix_table[] = { #if HAVE_XAPIAN_FIELD_PROCESSOR static Xapian::FieldProcessor * -_make_field_processor (const char *name, notmuch_database_t *notmuch) { +_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 (); else - return (new RegexpFieldProcessor (name, *notmuch->query_parser, notmuch))->release (); + return (new RegexpFieldProcessor (name, options, *notmuch->query_parser, notmuch))->release (); } #else -#define _make_field_processor(name, db) NULL +#define _make_field_processor(name, options, db) NULL #endif const char * @@ -1069,6 +1071,7 @@ notmuch_database_open_verbose (const char *path, 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); diff --git a/lib/regexp-fields.cc b/lib/regexp-fields.cc index b2b39504..a32b965e 100644 --- a/lib/regexp-fields.cc +++ b/lib/regexp-fields.cc @@ -114,13 +114,21 @@ static inline Xapian::valueno _find_slot (std::string prefix) return NOTMUCH_VALUE_FROM; else if (prefix == "subject") return NOTMUCH_VALUE_SUBJECT; + else if (prefix == "mid") + return NOTMUCH_VALUE_MESSAGE_ID; else throw Xapian::QueryParserError ("unsupported regexp field '" + prefix + "'"); } -RegexpFieldProcessor::RegexpFieldProcessor (std::string prefix, Xapian::QueryParser &parser_, notmuch_database_t *notmuch_) - : slot (_find_slot (prefix)), term_prefix (_find_prefix (prefix.c_str ())), - parser (parser_), notmuch (notmuch_) +RegexpFieldProcessor::RegexpFieldProcessor (std::string prefix, + notmuch_field_flag_t options_, + Xapian::QueryParser &parser_, + notmuch_database_t *notmuch_) + : slot (_find_slot (prefix)), + term_prefix (_find_prefix (prefix.c_str ())), + options (options_), + parser (parser_), + notmuch (notmuch_) { }; @@ -135,10 +143,16 @@ RegexpFieldProcessor::operator() (const std::string & str) throw Xapian::QueryParserError ("unmatch regex delimiter in '" + str + "'"); } } else { - /* TODO replace this with a nicer API level triggering of - * phrase parsing, when possible */ - std::string quoted='"' + str + '"'; - return parser.parse_query (quoted, NOTMUCH_QUERY_PARSER_FLAGS, term_prefix); + if (options & NOTMUCH_FIELD_PROBABILISTIC) { + /* TODO replace this with a nicer API level triggering of + * phrase parsing, when possible */ + std::string quoted='"' + str + '"'; + return parser.parse_query (quoted, NOTMUCH_QUERY_PARSER_FLAGS, term_prefix); + } else { + /* Boolean prefix */ + std::string term = term_prefix + str; + return Xapian::Query (term); + } } } #endif diff --git a/lib/regexp-fields.h b/lib/regexp-fields.h index bac11999..8a0e72e1 100644 --- a/lib/regexp-fields.h +++ b/lib/regexp-fields.h @@ -63,11 +63,13 @@ class RegexpFieldProcessor : public Xapian::FieldProcessor { protected: Xapian::valueno slot; std::string term_prefix; + int options; Xapian::QueryParser &parser; notmuch_database_t *notmuch; public: - RegexpFieldProcessor (std::string prefix, Xapian::QueryParser &parser_, notmuch_database_t *notmuch_); + RegexpFieldProcessor (std::string prefix, notmuch_field_flag_t options, + Xapian::QueryParser &parser_, notmuch_database_t *notmuch_); ~RegexpFieldProcessor () { }; -- 2.11.0