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 cD3OKZkOJWE05AAAgWs5BA (envelope-from ) for ; Tue, 24 Aug 2021 17:22:01 +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 uGdgJZkOJWFhZQAAbx9fmQ (envelope-from ) for ; Tue, 24 Aug 2021 15:22:01 +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 0A5F084DF for ; Tue, 24 Aug 2021 17:22:01 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 6BD9A2057E; Tue, 24 Aug 2021 11:20:58 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id E25882056B for ; Tue, 24 Aug 2021 11:20:50 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id DC6875FD5C; Tue, 24 Aug 2021 11:20:50 -0400 (EDT) Received: (nullmailer pid 2942834 invoked by uid 1000); Tue, 24 Aug 2021 15:17:51 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 04/36] lib: define notmuch_query_create_with_syntax Date: Tue, 24 Aug 2021 08:17:13 -0700 Message-Id: <20210824151745.2941868-5-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: JCZUZ7EEZQ3RLTZ5BVKCI4NLS7JBMUIP X-Message-ID-Hash: JCZUZ7EEZQ3RLTZ5BVKCI4NLS7JBMUIP 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=1629818521; 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=LrmBx6WDneXj0tdjLafN2jjUV1qStGysdWcKBv/cVn8=; b=S3NfZbFWR5qr8YlcLFh19qsQmCJKd3Ylu93ZhVZ+IFPhX2QoSaRYyqrcCF7TRrgmTiwjxC ywL0VwNsg6WEDwRHj4MlmmBRCQ0LIx4jfqPi3BrvkqTYIzI4QEQjmp6S3q00e28bAz5kfn gQmeznH72frL+iAYQEpb4EVIhkRzrXHyq0s1+SkW9SecU0NxCWLZJqO18VUVf0zoMla7YP J46wQvt+GY1dTXqcYOzhkewgukq5RJmTqgOa6zIIUuLeGcDiJhm+5RZlPxS6IsSsRQmWBb izCrowP26T5lpB9Bklx2aiULMM/TF2KZGJUploRa3CGXiBAeRKFOYNdfuDH3ww== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1629818521; a=rsa-sha256; cv=none; b=YqFmJDV566P3o9KcvP0KxRRyOBHB8yxExgxUNY9nFTh9kEBJ8zmiC3nzSXlBXjgCZ3ypRO F6z5wFuC1xEqOXTcTp1KbFjWhl3wmxSHjaFszcmqOu24YeG1V9f8b7u1ydtRvPrq2FRTe/ edZsYlgJDSrL22aMP0IqPmqmbbRNoMDh4HpACWxGRjAZ6YV27fQLlT/BiWB953JTUZnFOr yrR71G7s/WIKjbN4NMyZFB2a8EzIHNnrBOh/M4Hw8jk/CkHOqZqog+bk3cY3V8F92yzeSJ AbAYqu/Z1o8a7wLFm/7vz4Hg3YcGNdDh08RijLiiffjZH+CoBFVdbU1+ktT0zQ== 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.00 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: 0A5F084DF X-Spam-Score: -1.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: ruMM/y9OdRVm Set the parsing syntax when the (notmuch) query object is created. Initially the library always returns a trivial query that matches all messages when using s-expression syntax. It seems better to select the syntax at query creation time because the lazy parsing is an implementation detail. --- lib/notmuch.h | 10 +++++++ lib/query.cc | 75 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index ef11ed1b..2f1ee951 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -961,6 +961,16 @@ notmuch_query_t * notmuch_query_create (notmuch_database_t *database, const char *query_string); +typedef enum { + NOTMUCH_QUERY_SYNTAX_XAPIAN, + NOTMUCH_QUERY_SYNTAX_SEXP +} notmuch_query_syntax_t; + +notmuch_status_t +notmuch_query_create_with_syntax (notmuch_database_t *database, + const char *query_string, + notmuch_query_syntax_t syntax, + notmuch_query_t **output); /** * Sort values for notmuch_query_set_sort. */ diff --git a/lib/query.cc b/lib/query.cc index 39b85e91..a3fe3793 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -23,6 +23,10 @@ #include /* GHashTable, GPtrArray */ +#if HAVE_SFSEXP +#include "sexp.h" +#endif + struct _notmuch_query { notmuch_database_t *notmuch; const char *query_string; @@ -30,6 +34,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; }; @@ -105,7 +110,10 @@ _notmuch_query_constructor (notmuch_database_t *notmuch, query->notmuch = notmuch; - query->query_string = talloc_strdup (query, query_string); + if (query_string) + query->query_string = talloc_strdup (query, query_string); + else + query->query_string = NULL; query->sort = NOTMUCH_SORT_NEWEST_FIRST; @@ -121,20 +129,49 @@ notmuch_query_create (notmuch_database_t *notmuch, const char *query_string) { - notmuch_query_t *query = _notmuch_query_constructor (notmuch, query_string); + notmuch_query_t *query; + notmuch_status_t status; - if (! query) + status = notmuch_query_create_with_syntax (notmuch, query_string, + NOTMUCH_QUERY_SYNTAX_XAPIAN, + &query); + if (status) return NULL; return query; } -static notmuch_status_t -_notmuch_query_ensure_parsed (notmuch_query_t *query) +notmuch_status_t +notmuch_query_create_with_syntax (notmuch_database_t *notmuch, + const char *query_string, + notmuch_query_syntax_t syntax, + notmuch_query_t **output) { - if (query->parsed) - return NOTMUCH_STATUS_SUCCESS; + notmuch_query_t *query; + + if (! output) + return NOTMUCH_STATUS_NULL_POINTER; + + query = _notmuch_query_constructor (notmuch, query_string); + if (! query) + return NOTMUCH_STATUS_OUT_OF_MEMORY; + + if (syntax == NOTMUCH_QUERY_SYNTAX_SEXP && ! HAVE_SFSEXP) { + _notmuch_database_log (notmuch, "sexp query parser not available"); + return NOTMUCH_STATUS_ILLEGAL_ARGUMENT; + } + + query->syntax = syntax; + + *output = query; + + return NOTMUCH_STATUS_SUCCESS; +} + +static notmuch_status_t +_notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) +{ try { query->xapian_query = query->notmuch->query_parser-> @@ -167,6 +204,30 @@ _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) +{ + if (query->parsed) + return NOTMUCH_STATUS_SUCCESS; + + 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 HAVE_SFSEXP + if (query->syntax == NOTMUCH_QUERY_SYNTAX_SEXP) + return _notmuch_query_ensure_parsed_sexpr (query); +#endif + + return _notmuch_query_ensure_parsed_xapian (query); +} + const char * notmuch_query_get_query_string (const notmuch_query_t *query) { -- 2.32.0