From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id yJtyMwGV82ARFQAAgWs5BA (envelope-from ) for ; Sun, 18 Jul 2021 04:42:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id OKAlLwGV82A1GgAAB5/wlQ (envelope-from ) for ; Sun, 18 Jul 2021 02:42:09 +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 8641B22984 for ; Sun, 18 Jul 2021 04:42:09 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id DBD572A0DB; Sat, 17 Jul 2021 22:41:25 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 0F56329322 for ; Sat, 17 Jul 2021 22:40:48 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 04EE15FD21; Sat, 17 Jul 2021 22:40:47 -0400 (EDT) Received: (nullmailer pid 3853949 invoked by uid 1000); Sun, 18 Jul 2021 02:40:27 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 14/25] lib/parse-sexp: handle saved queries Date: Sat, 17 Jul 2021 23:40:10 -0300 Message-Id: <20210718024021.3850340-15-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: HYEVUMMP2NLIOGCQXAGULAJ4RJ5EHQC7 X-Message-ID-Hash: HYEVUMMP2NLIOGCQXAGULAJ4RJ5EHQC7 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=1626576129; 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=zA8PIyQMUyipCHtCcJchkbWZvSK/9fzCcKrTu6r/Kxg=; b=WD4KU0PnhO7gHBJ5BVRII+es7+WH0bMNjPtBwQeg2WeH159l4YnD50grndDHPY79xOqJUH ywXuKhejc8fQCS30h4YnJ83lWNTIxKiHLjw2SPoGFv5arxZ/r8m5rtWzb0gym9iZHaLUj0 4SNtI7uhABY0Tst5ghcPgTGcTbmc9l4FfifGM5SLqKBK7AutlfFM2UjzMfDJKabbb0SmnE BQxJmn+I8+K9rvFO4ukB7Eeq+MvCrBbvlNWdZtvJ2OsUDj3AP4F3k6PVkOE/Aqcf+nvH1v kO2VQQeKom+imM7ujxK2CBrB1USmbFUEtbXWQ0JZFH0r9soJb7M24edkIvU26g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626576129; a=rsa-sha256; cv=none; b=bm35nTLZ8rRnRO/BWdCt0mhQzBYbU/aMLMssn6OnotvZOUfCcU7/3pvcaxxB2W8U99ZQ/P t+r1HEXcQaBkXMDgWF3Q7UcCf0yYWYTepEr2ryi7JJfxjf4M5FHyOe9FU6xfm5nKl+QJST BIq715eYh2szuwdyvqAZ3ZhfA7Y18vFEQwW0WAUOQa21e/WLxZ+dkR3v9HLXst3Q78DbE7 wTpK+oAOZej6OZlnJoS1y6VhiMJsoyuiD+gLJhcibetetr7OJdEytTGCPvA35TSTcezNDl wGd/CAQ4MDhxbt9T3ToiBQmT1opK9CA+pT4TqFArR9jOLaurKsm6yd5bOlPwxw== 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.05 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: 8641B22984 X-Spam-Score: -1.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: oekvWwh5HFQW This provides functionality analogous to query: in the Xapian QueryParser based parser. Perhaps counterintuitively, the saved queries currently have to be in the original query syntax (i.e. not s-expressions). --- lib/parse-sexp.cc | 10 ++++++++++ test/T081-sexpr-search.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index 29c5cd31..1be2a4be 100644 --- a/lib/parse-sexp.cc +++ b/lib/parse-sexp.cc @@ -2,6 +2,7 @@ #include "notmuch-private.h" #include "sexp.h" #include "parse-time-vrp.h" +#include "query-fp.h" typedef struct { const char *name; @@ -35,6 +36,7 @@ static _sexp_field_t fields[] = { "mimetype", Xapian::Query::OP_PHRASE }, { "path", Xapian::Query::OP_OR }, { "property", Xapian::Query::OP_AND }, + { "query", Xapian::Query::OP_INVALID }, { "subject", Xapian::Query::OP_PHRASE }, { "tag", Xapian::Query::OP_AND }, { "thread", Xapian::Query::OP_OR }, @@ -208,6 +210,14 @@ _sexp_to_xapian_query (notmuch_database_t *notmuch, const sexp_t *sx, Xapian::Qu if (strcasecmp (field->name, "date") == 0) { return _sexp_parse_date (notmuch, sx, output); } + if (strcasecmp (field->name, "query") == 0) { + if (! sx->list->next || ! sx->list->next->val) { + _notmuch_database_log (notmuch, "missing query name\n"); + return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; + } else { + return _notmuch_query_name_to_query (notmuch, sx->list->next->val, output); + } + } return _sexp_combine_field (_find_prefix (field->name), field->xapian_op, sx->list->next, output); diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index c9dd8f39..89f1c36f 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -153,6 +153,34 @@ notmuch search mimetype:text/html > EXPECTED notmuch search --query-syntax=sexp '(mimetype text html)' > OUTPUT test_expect_equal_file EXPECTED OUTPUT +QUERYSTR="date:2009-11-18..2009-11-18 and tag:unread" +QUERYSTR2="query:test and subject:Maildir" +notmuch config set --database query.test "$QUERYSTR" +notmuch config set query.test2 "$QUERYSTR2" + +test_begin_subtest "ill-formed named query search" +notmuch search --query-syntax=sexp '(query)' > OUTPUT 2>&1 +cat < EXPECTED +notmuch search: Syntax error in query +missing query name +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "search named query" +notmuch search --query-syntax=sexp '(query test)' > OUTPUT +notmuch search $QUERYSTR > EXPECTED +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "search named query with other terms" +notmuch search --query-syntax=sexp '(and (query test) (subject Maildir))' > OUTPUT +notmuch search $QUERYSTR and subject:Maildir > EXPECTED +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "search nested named query" +notmuch search --query-syntax=sexp '(query test2)' > OUTPUT +notmuch search $QUERYSTR2 > EXPECTED +test_expect_equal_file EXPECTED OUTPUT + test_begin_subtest "Search by 'subject'" add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' output=$(notmuch search --query-syntax=sexp '(subject subjectsearchtest)' | notmuch_search_sanitize) -- 2.30.2