From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id oHd8IAuV82CZGAAAgWs5BA (envelope-from ) for ; Sun, 18 Jul 2021 04:42:19 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id uB8lHAuV82CGXgAA1q6Kng (envelope-from ) for ; Sun, 18 Jul 2021 02:42:19 +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) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3769B1E82B for ; Sun, 18 Jul 2021 04:42:19 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 1BE642A14E; Sat, 17 Jul 2021 22:41:33 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 19A07293A6 for ; Sat, 17 Jul 2021 22:40:51 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id C49915FD21; Sat, 17 Jul 2021 22:40:50 -0400 (EDT) Received: (nullmailer pid 3853947 invoked by uid 1000); Sun, 18 Jul 2021 02:40:27 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 13/25] lib: factor out expansion of saved queries. Date: Sat, 17 Jul 2021 23:40:09 -0300 Message-Id: <20210718024021.3850340-14-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210718024021.3850340-1-david@tethera.net> References: <20210718024021.3850340-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: GRIM5NKBJDPDNF3AKEKPVRVHTQSNBS24 X-Message-ID-Hash: GRIM5NKBJDPDNF3AKEKPVRVHTQSNBS24 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=1626576139; 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=/NhvhKkDjM0s0pd/53Xfd3u7Mczvgs/JUnQyJSeBej0=; b=BPtiJotXcbo7Y8WHvFY8qtzZ5A8Bx1mQQf4BpBVvZwEdiaCPsaK+SKAaF6SCkC8COtpYqj 8nh8FGeitouU0cK1gbxkUahUswOsbCSzfxY8JEkG2sb397PpZBoT0qBZXm8Z/xG/QGkLM3 29/62394ZfseG9ABvf7VV+KYXGvWZsWr8BrAQT2Nm014vEiPcVtYCMaJuPTFB/LH/5bf6/ +v8CBiK5wZ7cVEvTib8jej32RYj3M1nIG4hUIchqKbFkRrOvqLz4S7yQloLuqDtM3FI1QK fMDoc1a7zuoR/Ox/z7MSrFhpGHj5El9MatKK/2AjhC2j+AOUCSYOuVgu42vseg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626576139; a=rsa-sha256; cv=none; b=r2U869R0ndlwjYq3JnvU9BXbUEIwByt7JV4iwlr+es2TawEvBebBYn0djtiHMQ/JJNfIhH 8WhvMz/gWpx+qIks82PfQmCAHAmW8R5NvftlcU4GE/9UiocPN375cJK4vTV2gOjxf7fS5s mrWFS8X+lCtH7bjVgXTTKmmBqM+PA+EUt0uliQuxZqam1LHxAC7oUPYm0wr9BC42e2sFd1 1hHcd6lAyEXJS/Xlarx/JEp8b2bOyUWdSZGDxT5qxv4GCkOtPVYZzSvbvA4i0PS6VL07fq MQut+4sjpNsZZhgW8t+c41XSNZvwKkC4Wz+6FDeW+8VKq/ihMvYZCyIomEmtEQ== ARC-Authentication-Results: i=1; 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-Spam-Score: -1.07 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: 3769B1E82B X-Spam-Score: -1.07 X-Migadu-Scanner: scn0.migadu.com X-TUID: hddnVz7dr/Ok This is intended to allow use outside of the Xapian query parser. --- lib/query-fp.cc | 22 +++++++++++++++++++--- lib/query-fp.h | 4 ++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/query-fp.cc b/lib/query-fp.cc index b980b7f0..75b1d875 100644 --- a/lib/query-fp.cc +++ b/lib/query-fp.cc @@ -24,17 +24,33 @@ #include "query-fp.h" #include -Xapian::Query -QueryFieldProcessor::operator() (const std::string & name) +notmuch_status_t +_notmuch_query_name_to_query (notmuch_database_t *notmuch, const std::string name, + Xapian::Query &output) { std::string key = "query." + name; char *expansion; notmuch_status_t status; status = notmuch_database_get_config (notmuch, key.c_str (), &expansion); + if (status) + return status; + + output = notmuch->query_parser->parse_query (expansion, NOTMUCH_QUERY_PARSER_FLAGS); + return NOTMUCH_STATUS_SUCCESS; +} + +Xapian::Query +QueryFieldProcessor::operator() (const std::string & name) +{ + notmuch_status_t status; + Xapian::Query output; + + status = _notmuch_query_name_to_query (notmuch, name, output); if (status) { throw Xapian::QueryParserError ("error looking up key" + name); } - return parser.parse_query (expansion, NOTMUCH_QUERY_PARSER_FLAGS); + return output; + } diff --git a/lib/query-fp.h b/lib/query-fp.h index beaaf405..a1b12bb9 100644 --- a/lib/query-fp.h +++ b/lib/query-fp.h @@ -26,6 +26,10 @@ #include #include "notmuch.h" +notmuch_status_t +_notmuch_query_name_to_query (notmuch_database_t *notmuch, const std::string name, + Xapian::Query &output); + class QueryFieldProcessor : public Xapian::FieldProcessor { protected: Xapian::QueryParser &parser; -- 2.30.2