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 OMNqJgiV82CZGAAAgWs5BA (envelope-from ) for ; Sun, 18 Jul 2021 04:42:16 +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 eAsUIgiV82CTFAAAbx9fmQ (envelope-from ) for ; Sun, 18 Jul 2021 02:42:16 +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 32E871C260 for ; Sun, 18 Jul 2021 04:42:16 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 0977A2A149; Sat, 17 Jul 2021 22:41:31 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id E013E290BB for ; Sat, 17 Jul 2021 22:40:49 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id D6C2A5FD21; Sat, 17 Jul 2021 22:40:49 -0400 (EDT) Received: (nullmailer pid 3853925 invoked by uid 1000); Sun, 18 Jul 2021 02:40:27 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 03/25] lib: define notmuch_query_create_sexpr Date: Sat, 17 Jul 2021 23:39:59 -0300 Message-Id: <20210718024021.3850340-4-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: 4BXGBYYQFXC4QBWKIEA23WL6KXBX5WFX X-Message-ID-Hash: 4BXGBYYQFXC4QBWKIEA23WL6KXBX5WFX 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=1626576136; 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=c+MON2r8OH/08xSAyVknQCurdQwIZk7oBB/Rh3NsaXA=; b=FRUk892aVXm7Zfg/A9iiydzq0ka2jbo1aB9F9GYiXSYw1g2TSoBg1/gbXlfaKTWdYvocED X4FC37fhX/+iLYxcWGcw535QEctc8ry8SfBvt4One41pFiBJoXITM3TazYJJmS8vjcKv1i egtgA6Vc//HWIZRLEZ+g1Np89OVHS2L/zJzVc8npTfEhFiqZ69mpAq9aC7rJpLSQLQHmpw DPLH32d8QGVkhBUI22UL9oho8O8Fay7MojsBfZDibFYpS+QR7XGP6/OO9RDqrwTFq9bj+w VWycDaXjy8Yet8MaoKFo9EKNOQzTtqYaMtxZt30giKU+1BhuYB4LJhj0z8urxQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626576136; a=rsa-sha256; cv=none; b=BHJI0b/1ucsJA2Xr0Tq7UrM8Q+LO84seTkerWF1dv8N9HUUsG4OIVnUSUm11JluWHmHWcM PfIBaiecWN+ogzTflwvgaF6QCJab6IaS4I3AsFPH5Z+/wd6TcoiFLBGlcxs4qKMYl6mypo DFyeRcoWoE/cUyFUXHuwHM1L08yBWAWhcygcbZSN5gC1aHpYPEq7GNCdYIXDsC1Otmlxg9 QYuhBTVwcivBo54icGns7p3v9yw2wXk88fXVt76CSDH4QofitfD3GCT0LZk8ZE2+EVyCgY xZzNL+poC7laEf/DWu//N4IZ0ZDWgnSZ4ZUPZywreLonhxFybo4cD1+zLcYcrg== 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: 32E871C260 X-Spam-Score: -1.07 X-Migadu-Scanner: scn1.migadu.com X-TUID: KJUm0VbLSe2t 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 | 52 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 52 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..d05bd193 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,28 @@ _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 (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