From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id eEUREzb3A2HEgwEAgWs5BA (envelope-from ) for ; Fri, 30 Jul 2021 14:57:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id uJSkDjb3A2FyNQAAbx9fmQ (envelope-from ) for ; Fri, 30 Jul 2021 12:57:26 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E7A34DC99 for ; Fri, 30 Jul 2021 14:57:25 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id B408829215; Fri, 30 Jul 2021 08:56:43 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 2389C291EC for ; Fri, 30 Jul 2021 08:56:22 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 15B965FD17; Fri, 30 Jul 2021 08:56:22 -0400 (EDT) Received: (nullmailer pid 2166908 invoked by uid 1000); Fri, 30 Jul 2021 12:56:10 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 21/27] lib/query: factor out _notmuch_query_string_to_xapian_query Date: Fri, 30 Jul 2021 09:56:01 -0300 Message-Id: <20210730125607.2165433-22-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210730125607.2165433-1-david@tethera.net> References: <20210730125607.2165433-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: AS7DM7RDHTWIKQPGQ7NOP47IERTO3DKT X-Message-ID-Hash: AS7DM7RDHTWIKQPGQ7NOP47IERTO3DKT X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1627649846; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=O1ZtlngVONyzZUEmPIPaZ9/9Ov1dfNZqPwWfHpeMwbk=; b=CGzljLMknjAy/2NXSXrZQoZfwS7rCZxi1K9uSELlHxc893a/cntzlf+Qs1IAmoYNbO/2yw fydGih7XSi5vPl/6MN0fKXPmoOt9l06mYcwG8XHtgKlK9tLz8b54UnxsRrNM2EKJXoIyVp mJ08O57OpaYyFYvTrVquBzoi/+LImAgfHRI77RamxVnBSzaqYFGFwyIY7lq/cHeL1w9D6R g5hewa0NOOE94Gfy2/mHj/PGf1dJAVlprCPdJ1P3QXnSnoA3eL+v7aBVu85NJnw7U2FRYP 5fWDuE9CN+XaTROk4BJH8ERsKXtuZ0G50zjf0KhXi66OZluV6NPx7hvFJiRbZw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1627649846; a=rsa-sha256; cv=none; b=cPSglbS86Av0gN4B0/zRXUjDUIZXID7fb7Xn+w9lwyo2qaMvR6UeTCQJhHW2zU7Upxi55l 0+NPMoDcbLHi8QgqI7fpObovi0FyVUJEdbCWIB7000NUylIwjvIOg31+zLEVp/v9IegEGE YWAHzVQjEqdk5q60u5Oc+aoXJUJndM7AXlRuM8uOZ0yZHkYthQukBVZjDjX2sl2zr5fQwF V0yGDPp0UePJpHyjhkmlM0g3VtgKxpsAH/lIkMf5XpTExMGVBihvPEmilA+Px+fjZdQ1zN hw9zz1ZNWG9tzbPKRn+dModXGwaoKXTpjkwWVvc9J/DaeTv5q2c5J65nElrjuA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 0.52 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: E7A34DC99 X-Spam-Score: 0.52 X-Migadu-Scanner: scn1.migadu.com X-TUID: xo073Ri3HmFX When dealing with recursive queries (i.e. thread:{foo}) it turns out to be useful just to deal with the underlying Xapian objects, and not wrap them in notmuch objects. --- lib/database-private.h | 7 ++++++ lib/query.cc | 51 ++++++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/lib/database-private.h b/lib/database-private.h index cf4eb94b..7ee8e62d 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -302,11 +302,18 @@ notmuch_status_t _notmuch_database_setup_user_query_fields (notmuch_database_t *notmuch); #if __cplusplus +/* query.cc */ +notmuch_status_t +_notmuch_query_string_to_xapian_query (notmuch_database_t *notmuch, + std::string query_string, + Xapian::Query &output, + std::string &msg); /* parse-sexp.cc */ notmuch_status_t _notmuch_sexp_string_to_xapian_query (notmuch_database_t *notmuch, const char *querystr, Xapian::Query &output); +/* regexp-fields.cc */ notmuch_status_t _notmuch_regexp_to_query (notmuch_database_t *notmuch, Xapian::valueno slot, std::string field, std::string regexp_str, diff --git a/lib/query.cc b/lib/query.cc index 57596f48..87ee18fc 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -178,38 +178,55 @@ _notmuch_query_cache_terms (notmuch_query_t *query) query->terms.insert (*t); } -static notmuch_status_t -_notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) +notmuch_status_t +_notmuch_query_string_to_xapian_query (notmuch_database_t *notmuch, + std::string query_string, + Xapian::Query &output, + std::string &msg) { try { - if (strcmp (query->query_string, "") == 0 || - strcmp (query->query_string, "*") == 0) { - query->xapian_query = Xapian::Query::MatchAll; + if (query_string == "" || query_string == "*") { + output = Xapian::Query::MatchAll; } else { - query->xapian_query = - query->notmuch->query_parser-> - parse_query (query->query_string, NOTMUCH_QUERY_PARSER_FLAGS); - - _notmuch_query_cache_terms (query); + output = + notmuch->query_parser-> + parse_query (query_string, NOTMUCH_QUERY_PARSER_FLAGS); } - query->parsed = true; - } catch (const Xapian::Error &error) { - if (! query->notmuch->exception_reported) { - _notmuch_database_log (query->notmuch, + if (! notmuch->exception_reported) { + _notmuch_database_log (notmuch, "A Xapian exception occurred parsing query: %s\n", error.get_msg ().c_str ()); - _notmuch_database_log_append (query->notmuch, + _notmuch_database_log_append (notmuch, "Query string was: %s\n", - query->query_string); - query->notmuch->exception_reported = true; + query_string.c_str ()); + notmuch->exception_reported = true; } + msg = error.get_msg (); return NOTMUCH_STATUS_XAPIAN_EXCEPTION; } return NOTMUCH_STATUS_SUCCESS; } +static notmuch_status_t +_notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) +{ + notmuch_status_t status; + std::string msg; /* ignored */ + + status = _notmuch_query_string_to_xapian_query (query->notmuch, query->query_string, + query->xapian_query, msg); + if (status) + return status; + + query->parsed = true; + + _notmuch_query_cache_terms (query); + + return NOTMUCH_STATUS_SUCCESS; +} + static notmuch_status_t _notmuch_query_ensure_parsed_sexpr (notmuch_query_t *query) { -- 2.30.2