From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id oFpTOchVFWGJNwEAgWs5BA (envelope-from ) for ; Thu, 12 Aug 2021 19:09:28 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id uE4ZNchVFWGicAAA1q6Kng (envelope-from ) for ; Thu, 12 Aug 2021 17:09:28 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A307E35DB for ; Thu, 12 Aug 2021 19:09:28 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 54B51298FC; Thu, 12 Aug 2021 13:08:45 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 37D93299B3 for ; Thu, 12 Aug 2021 13:08:39 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 2FD9E5FD5C; Thu, 12 Aug 2021 13:08:39 -0400 (EDT) Received: (nullmailer pid 1348765 invoked by uid 1000); Thu, 12 Aug 2021 17:07:43 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 21/31] lib/query: factor out _notmuch_query_string_to_xapian_query Date: Thu, 12 Aug 2021 10:07:18 -0700 Message-Id: <20210812170728.1348333-22-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210812170728.1348333-1-david@tethera.net> References: <20210812170728.1348333-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: M5OYP3TRPT3SJJCVUJWZC5SCMARZ7NB7 X-Message-ID-Hash: M5OYP3TRPT3SJJCVUJWZC5SCMARZ7NB7 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=1628788168; 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=uPK5kEjfhOCUIOeclKi8+nzBmxbfqXWGO524WSHrhd43Ycv1oJOz2LB1eb3sN2Pa5x6ery mPFhV9UEBZCc+9G5ejJ02Lc6U85XMCmrHTL7XmkrpHXaEijVyZrSX1s6X2ExnPQ1l68Hcu eaqACyaHngDZKzVBJ6JFpT8rlXx9RIXv1GeL1PT4vt8AoBVuYPxqDMIFI6xSnaz8q/u1fQ feOuSu00id0aF1TzbNI9rfZHWBRPxgQEb+QN5I4YNXI5VD3Je+bpLZd77kLhjblc70dLyk 4meA1FJ1Jjgk/H/xfcwQ1+x65IiWRIsQsHl7f/gRsfwtTaZjU8MnCYjFNGtsBQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628788168; a=rsa-sha256; cv=none; b=qHcoWP5tMv2u/tnQ7yXVUTT5dMFCiLAy4yG41h9oTApWVbhRBdQ8LEUkxA+5f8xiao7yF3 fknI2Pmchqqsk34BrLTusJYIy7XHMmCqkgxPoMG8HX+1bLsBkzlz8kb34uNfGU/hdZ9NRv 9mdRpihEWPgP0uOIxQyi/xZeRGuF2dZFSNRwEp9UNXaGaKCiN6rD4B5OTCCtDiWPApojoY +bXpqjbnqI3BrdEtr8owwsPajqQyFVyCjiSqx1apCOfAX15d1o9YCd93yvng0/skfNpVc0 wH9E7VVXWpqBuxvi/+1XzOP0NMyR5jlGaUsQEOpp6HfIPkR9jVP6p8HYHja3ZA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 0.48 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A307E35DB X-Spam-Score: 0.48 X-Migadu-Scanner: scn0.migadu.com X-TUID: j5omtowt4sig 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