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 kBlqKN8p7mD3egAAgWs5BA (envelope-from ) for ; Wed, 14 Jul 2021 02:03:43 +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 2JosJN8p7mAhRwAA1q6Kng (envelope-from ) for ; Wed, 14 Jul 2021 00:03:43 +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 54A1FCC83 for ; Wed, 14 Jul 2021 02:03:43 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 358562910F; Tue, 13 Jul 2021 20:03:11 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id B9F1B29083 for ; Tue, 13 Jul 2021 20:02:50 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id B20645FD21; Tue, 13 Jul 2021 20:02:50 -0400 (EDT) Received: (nullmailer pid 804652 invoked by uid 1000); Wed, 14 Jul 2021 00:02:42 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 03/11] lib: define notmuch_query_create_sexpr Date: Tue, 13 Jul 2021 21:02:31 -0300 Message-Id: <20210714000239.804384-4-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210714000239.804384-1-david@tethera.net> References: <20210714000239.804384-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: JKCXO75ICQXAXQ4C4F7FREUUTZAK36BR X-Message-ID-Hash: JKCXO75ICQXAXQ4C4F7FREUUTZAK36BR 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=1626221023; 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=kwCndN6gMEFJd+aUW1eydPglQt3rMIoJcaK0MbCXACU=; b=CTMph777yVTVJA7L+Q9PauUgK+ZItmypY8fVhdvM4v5txxfUFl7Et6bPqrOP4zfKyuRB7c vF9UEcgUWq7okpxg93Bjrd+u9dDDmYtTMa8eDvkZMwipledvmj8AMFyNTt8EvFCyAIh5lb dtPxoAA7Dkvs94KpncbWrXR04H4W06d0h9sFoBAhB45WwIFOHVocy5lZbBV3GYwJ01bftA GLk1/q2R2sM/qofSQvDToQAgVxu3ildQxa5TuyKXG+8CVnTQoOwBG7by/ZyXFsdk7piSEJ vIOy7sF2waqK5UTDGk+MjHs/7kVnhWy0xgStNx3mjHjUTPvbtHdLrRtphn7ORw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626221023; a=rsa-sha256; cv=none; b=ZvBwxpu1n+Mmb8yzufFCOXeLvMsfOmwYZ1oms80z2+2OSmw+aHMlxf7JjCQYiajCkt1MtM 28lF05qSQOpP7uIgiLy6k0ENpuclxGxhXxpcttVCaBSoivVxippptOmiorMxYxKJRAUw/o 1ul0iBDoaOlfe8raIzOY2fAV/pTNpjKMFDV132yUjOQxV7S+k3Zx/B9YcYgnb0I3IVva0k b3Hr33C2SV2Y18lQMx321gd9FrVHinE4lsS3dU+rK3Vx6y0452H/XpMhR1eN2BrrjM1pv3 eLpaJwI2fVH4VcvBfyPOX+e74113Xx1/5bOWKreP90IqGiFdGu1ywEFdU/WFNw== 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: -1.08 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: 54A1FCC83 X-Spam-Score: -1.08 X-Migadu-Scanner: scn0.migadu.com X-TUID: 20mX/hRIurY7 Set the parsing syntax when the (notmuch) query object is created. Initially the library always returns a trivial query that matches all messages. --- lib/notmuch.h | 4 ++++ lib/query.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index 3b28bea3..a9abdd18 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -961,6 +961,10 @@ notmuch_query_t * notmuch_query_create (notmuch_database_t *database, const char *query_string); +notmuch_query_t * +notmuch_query_create_sexpr (notmuch_database_t *database, + const char *query_string); + /** * Sort values for notmuch_query_set_sort. */ diff --git a/lib/query.cc b/lib/query.cc index 39b85e91..9d2b6e50 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -23,6 +23,13 @@ #include /* GHashTable, GPtrArray */ +#include "sexp.h" + +typedef enum { + NOTMUCH_QUERY_SYNTAX_XAPIAN, + NOTMUCH_QUERY_SYNTAX_SEXPR, +} notmuch_query_syntax_t; + struct _notmuch_query { notmuch_database_t *notmuch; const char *query_string; @@ -30,6 +37,7 @@ struct _notmuch_query { notmuch_string_list_t *exclude_terms; notmuch_exclude_t omit_excluded; bool parsed; + notmuch_query_syntax_t syntax; Xapian::Query xapian_query; std::set terms; }; @@ -126,15 +134,29 @@ notmuch_query_create (notmuch_database_t *notmuch, if (! query) return NULL; + query->syntax = NOTMUCH_QUERY_SYNTAX_XAPIAN; + return query; } -static notmuch_status_t -_notmuch_query_ensure_parsed (notmuch_query_t *query) +notmuch_query_t * +notmuch_query_create_sexpr (notmuch_database_t *notmuch, + const char *query_string) { - if (query->parsed) - return NOTMUCH_STATUS_SUCCESS; + notmuch_query_t *query = _notmuch_query_constructor (notmuch, query_string); + + if (! query) + return NULL; + + query->syntax = NOTMUCH_QUERY_SYNTAX_SEXPR; + + return query; +} + +static notmuch_status_t +_notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) +{ try { query->xapian_query = query->notmuch->query_parser-> @@ -167,6 +189,25 @@ _notmuch_query_ensure_parsed (notmuch_query_t *query) return NOTMUCH_STATUS_SUCCESS; } +static notmuch_status_t +_notmuch_query_ensure_parsed_sexpr (notmuch_query_t *query) +{ + query->xapian_query = Xapian::Query::MatchAll; + return NOTMUCH_STATUS_SUCCESS; +} + +static notmuch_status_t +_notmuch_query_ensure_parsed (notmuch_query_t *query) +{ + if (query->parsed) + return NOTMUCH_STATUS_SUCCESS; + + if (query->syntax == NOTMUCH_QUERY_SYNTAX_SEXPR) + return _notmuch_query_ensure_parsed_sexpr (query); + + return _notmuch_query_ensure_parsed_xapian (query); +} + const char * notmuch_query_get_query_string (const notmuch_query_t *query) { -- 2.30.2