From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 6BZTA8wOJWE05AAAgWs5BA (envelope-from ) for ; Tue, 24 Aug 2021 17:22:52 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 0Cx9OssOJWFBZQAAbx9fmQ (envelope-from ) for ; Tue, 24 Aug 2021 15:22:51 +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)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B23EF855C for ; Tue, 24 Aug 2021 17:22:51 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 1AAB9268C6; Tue, 24 Aug 2021 11:21:23 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 4301F204FE for ; Tue, 24 Aug 2021 11:21:18 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 3CBA45FD5C; Tue, 24 Aug 2021 11:21:18 -0400 (EDT) Received: (nullmailer pid 2942873 invoked by uid 1000); Tue, 24 Aug 2021 15:17:51 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 22/36] lib/query: factor out _notmuch_query_string_to_xapian_query Date: Tue, 24 Aug 2021 08:17:31 -0700 Message-Id: <20210824151745.2941868-23-david@tethera.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210824151745.2941868-1-david@tethera.net> References: <20210824151745.2941868-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: DRORRXD77EHI27KKPNX3LTVQUP3WW6FM X-Message-ID-Hash: DRORRXD77EHI27KKPNX3LTVQUP3WW6FM 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=1629818571; 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=JDoNiUEqPkVW0J/sogFhFWXM6Q3NF11bsE3hSpqJC7Y=; b=hHOjgdMOk6qalksB6A0PXwimOczCfvQkq0DjaOM+WuymQ8pDdIPOwsBH2zRw2r1cHTqMbs 3eAy/3rL/Kcx0SlSPNr1OdEwQJcphwJojTw3XwdxwFz5XnR+ihR58qeezkRPmQfPCCdbKk EV6yPXhjVnF978f8FB/OslQLbzJkyhcqTdkMMzG2rpBKjZheKiin05qLyZt/2/fI8+O0A7 GyGTn0ZKZ4sxPScrZ2ha2+0hLNXV/9hBdMDulJ0o02YNCW5ta0t78DK3o8TUSZmkvJFL0o UzlU/sj313yNVzePm/ToDvkaDewcm997hmRcAUFJIdteCJJxMUJpjj8MV+qozA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1629818571; a=rsa-sha256; cv=none; b=ctZV+HL8ah815zgGopscSs6gQv+QMdDoDbMJ3gOhDEdepiHe1HHw+hbLrgsWtRRU8IJD++ K7eaM//B+aYVs3gc7ggN/6fVGyV8Jl/Bcr/NIYJFhsJfvfGT38jVXkQOY44M/t0kTqI9IY idHpzlvJoYmd5I83eEFA6P+P1N5mdp5gycxxRHd5P7peTpC5E5gSumL26bCWQhqGhdc/MI baKmXqC0gQUQmfNvBeWO1WnKTeL4lwiO2erfFe4JNQ1cN/PCTg7FSzkD5fcivLti8M1yZL m7wbg7es6y6Eyv6xok7WH33+R3NwM32lewGKkkBJO6MiwlZB+LOYnG7rH9ojNQ== ARC-Authentication-Results: i=1; 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-Spam-Score: -0.93 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: B23EF855C X-Spam-Score: -0.93 X-Migadu-Scanner: scn0.migadu.com X-TUID: DNb8vM7F4bcW 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.32.0