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 A323641A557 for ; Wed, 22 Dec 2010 22:00:53 -0800 (PST) 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 KRu6E21Pl0aF for ; Wed, 22 Dec 2010 22:00:51 -0800 (PST) Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU [18.7.68.36]) by olra.theworths.org (Postfix) with ESMTP id CA5C8431FB6 for ; Wed, 22 Dec 2010 22:00:49 -0800 (PST) X-AuditID: 12074424-b7b0bae000000a05-76-4d12e590d017 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-7.mit.edu (Symantec Brightmail Gateway) with SMTP id D6.28.02565.095E21D4; Thu, 23 Dec 2010 01:00:48 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id oBN60lVr002450; Thu, 23 Dec 2010 01:00:47 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id oBN60kOj004800 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Thu, 23 Dec 2010 01:00:47 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72) (envelope-from ) id 1PVeEI-00024I-Ma; Thu, 23 Dec 2010 01:00:46 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 2/2] Replace Xapian query parser with custom query parser. Date: Thu, 23 Dec 2010 01:00:24 -0500 Message-Id: <1293084024-7893-3-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1293084024-7893-1-git-send-email-amdragon@mit.edu> References: <1293084024-7893-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: AAAAAA== Cc: amdragon@mit.edu 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: Thu, 23 Dec 2010 06:00:54 -0000 Note that the type:mail filter is implemented as a transform pass, so it no longer has to be done everywhere queries are parsed. Furthermore, this filter now depends on the prefixing logic in the query parser instead of implementing this itself. --- lib/database-private.h | 3 +-- lib/database.cc | 36 ++++++++++++++++++++++-------------- lib/query.cc | 42 ++++++++++++------------------------------ 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/lib/database-private.h b/lib/database-private.h index 358a71b..578d1fe 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -48,9 +48,8 @@ struct _notmuch_database { unsigned int last_doc_id; uint64_t last_thread_id; - Xapian::QueryParser *query_parser; Xapian::TermGenerator *term_gen; - Xapian::ValueRangeProcessor *value_range_processor; + _notmuch_qparser_t *query_parser; }; /* Return the list of terms from the given iterator matching a prefix. diff --git a/lib/database.cc b/lib/database.cc index f8245ab..d019777 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -571,6 +571,20 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch) return NOTMUCH_STATUS_SUCCESS; } +static _notmuch_token_t * +transform_type_mail (_notmuch_token_t *root, void *opaque) +{ + _notmuch_token_t *nroot, + *mail_ast = _notmuch_token_create (root, TOK_LIT, "mail"); + mail_ast->prefix = talloc_strdup (root, _find_prefix ("type")); + if (!root) + return mail_ast; + nroot = _notmuch_token_create (root, TOK_AND, NULL); + nroot->left = mail_ast; + nroot->right = root; + return nroot; +} + notmuch_database_t * notmuch_database_open (const char *path, notmuch_database_mode_t mode) @@ -661,27 +675,24 @@ notmuch_database_open (const char *path, INTERNAL_ERROR ("Malformed database last_thread_id: %s", str); } - notmuch->query_parser = new Xapian::QueryParser; notmuch->term_gen = new Xapian::TermGenerator; notmuch->term_gen->set_stemmer (Xapian::Stem ("english")); - notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); - - notmuch->query_parser->set_default_op (Xapian::Query::OP_AND); - notmuch->query_parser->set_database (*notmuch->xapian_db); - notmuch->query_parser->set_stemmer (Xapian::Stem ("english")); - notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME); - notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor); + notmuch->query_parser = _notmuch_qparser_create (notmuch, notmuch); for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) { prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i]; - notmuch->query_parser->add_boolean_prefix (prefix->name, - prefix->prefix); + _notmuch_qparser_add_db_prefix (notmuch->query_parser, prefix->name, + prefix->prefix, TRUE); } for (i = 0; i < ARRAY_SIZE (PROBABILISTIC_PREFIX); i++) { prefix_t *prefix = &PROBABILISTIC_PREFIX[i]; - notmuch->query_parser->add_prefix (prefix->name, prefix->prefix); + _notmuch_qparser_add_db_prefix (notmuch->query_parser, prefix->name, + prefix->prefix, FALSE); } + + _notmuch_qparser_add_transform (notmuch->query_parser, + transform_type_mail, NULL); } catch (const Xapian::Error &error) { fprintf (stderr, "A Xapian exception occurred opening database: %s\n", error.get_msg().c_str()); @@ -711,9 +722,6 @@ notmuch_database_close (notmuch_database_t *notmuch) } delete notmuch->term_gen; - delete notmuch->query_parser; - delete notmuch->xapian_db; - delete notmuch->value_range_processor; talloc_free (notmuch); } diff --git a/lib/query.cc b/lib/query.cc index c7ae4ee..d68e408 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -131,28 +131,19 @@ notmuch_query_search_messages (notmuch_query_t *query) talloc_set_destructor (messages, _notmuch_messages_destructor); Xapian::Enquire enquire (*notmuch->xapian_db); - Xapian::Query mail_query (talloc_asprintf (query, "%s%s", - _find_prefix ("type"), - "mail")); - Xapian::Query string_query, final_query; + _notmuch_token_t *ast; + Xapian::Query final_query; Xapian::MSet mset; - unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN | - Xapian::QueryParser::FLAG_PHRASE | - Xapian::QueryParser::FLAG_LOVEHATE | - Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE | - Xapian::QueryParser::FLAG_WILDCARD | - Xapian::QueryParser::FLAG_PURE_NOT); if (strcmp (query_string, "") == 0 || strcmp (query_string, "*") == 0) { - final_query = mail_query; + ast = NULL; } else { - string_query = notmuch->query_parser-> - parse_query (query_string, flags); - final_query = Xapian::Query (Xapian::Query::OP_AND, - mail_query, string_query); + ast = _notmuch_qparser_parse (notmuch->query_parser, query_string); } + ast = _notmuch_qparser_transform (notmuch->query_parser, ast); + final_query = _notmuch_qparser_generate (notmuch->query_parser, ast); enquire.set_weighting_scheme (Xapian::BoolWeight()); @@ -412,28 +403,19 @@ notmuch_query_count_messages (notmuch_query_t *query) try { Xapian::Enquire enquire (*notmuch->xapian_db); - Xapian::Query mail_query (talloc_asprintf (query, "%s%s", - _find_prefix ("type"), - "mail")); - Xapian::Query string_query, final_query; + _notmuch_token_t *ast; + Xapian::Query final_query; Xapian::MSet mset; - unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN | - Xapian::QueryParser::FLAG_PHRASE | - Xapian::QueryParser::FLAG_LOVEHATE | - Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE | - Xapian::QueryParser::FLAG_WILDCARD | - Xapian::QueryParser::FLAG_PURE_NOT); if (strcmp (query_string, "") == 0 || strcmp (query_string, "*") == 0) { - final_query = mail_query; + ast = NULL; } else { - string_query = notmuch->query_parser-> - parse_query (query_string, flags); - final_query = Xapian::Query (Xapian::Query::OP_AND, - mail_query, string_query); + ast = _notmuch_qparser_parse (notmuch->query_parser, query_string); } + ast = _notmuch_qparser_transform (notmuch->query_parser, ast); + final_query = _notmuch_qparser_generate (notmuch->query_parser, ast); enquire.set_weighting_scheme(Xapian::BoolWeight()); enquire.set_docid_order(Xapian::Enquire::ASCENDING); -- 1.7.2.3