From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id cDx3OzoOJWFm4gAAgWs5BA (envelope-from ) for ; Tue, 24 Aug 2021 17:20:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id qBQlNzoOJWHHYQAAbx9fmQ (envelope-from ) for ; Tue, 24 Aug 2021 15:20:26 +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 A656C87F7 for ; Tue, 24 Aug 2021 17:20:26 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 88C2120504; Tue, 24 Aug 2021 11:20:17 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 7BD7220058 for ; Tue, 24 Aug 2021 11:20:11 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 6CA6E5FD5C; Tue, 24 Aug 2021 11:20:11 -0400 (EDT) Received: (nullmailer pid 2942845 invoked by uid 1000); Tue, 24 Aug 2021 15:17:51 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 09/36] lib/parse-sexp: stem unquoted atoms Date: Tue, 24 Aug 2021 08:17:18 -0700 Message-Id: <20210824151745.2941868-10-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: I3HEOSNCGIX5KOKUCX2HHSNMEC573HQH X-Message-ID-Hash: I3HEOSNCGIX5KOKUCX2HHSNMEC573HQH 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=1629818426; 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=GYnFVxpy117wR41HgyBnaOD+0kuuubG8v40S3jd0Gco=; b=lPOdiHlw0UZRa7bCbX5rHCsCywOjGkYMQ3TF2sKRSDePHnwP4LbmgVNimd4a8WetcZFoPv Sal1TDeMPycvCt108EcEvqPD6eiTs/UonXX0NhrS6yjrrkJi2Zg7a0G76f7BbBrN1vxVrQ 8a28Z875612pijjL+FNqYA6g0Rdocx2x104kVfj+vGIWwX/medN8DAUpDdYsyG25AoiSr5 RBJXr9Cmtl0J/sSj9DZWT4osHGlKGgzvHHwAgQHoa60iKbjCE4VqpI5mAveVQrEtm8tV1K 9NPAcP8GQ+Asdq1XBFzxScsX0RNqwKqE/S9qExpIIP08XDawPGOcuI1WJN9lCg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1629818426; a=rsa-sha256; cv=none; b=a5CMg2YQb3l+NiGzomEx8xLQ2B1mRXnuIy4FF+t0ep6IaT5DaNL9aEir5ghitDnTPIxW7+ Bi1vuujCmizV3e4TWYHnkGvkvy5MzDgsnW//MpIsRz5MsVTVN8XRrsniUfhDQa/KOWuTuj 2+cMT+hcDc9rQvjzMlpPjvMjxWcSsQk8G6aMniSpsUEroLtzZQUBKNzIm1ltb516SfvBtL jnd/Ee6bH0vZaUhl4p3Drsi9ExW23JSiBEf4jcj5948pDdE0EMkQs7hGBdpoL2AFkGmvd3 26MA7h/Nc2mY1kmtBBdQr2WJskHgJTt52x5lKUROI+PPH3IWoD+S1ABMCwMQrQ== 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: -0.93 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: A656C87F7 X-Spam-Score: -0.93 X-Migadu-Scanner: scn0.migadu.com X-TUID: rf5SsnKmyAqx This is somewhat less DWIM than the Xapian query parser, but it has the advantage of simplicity. --- doc/man7/notmuch-sexp-queries.rst | 10 ++++++++-- lib/parse-sexp.cc | 10 +++++++--- test/T081-sexpr-search.sh | 5 ++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/doc/man7/notmuch-sexp-queries.rst b/doc/man7/notmuch-sexp-queries.rst index 1118f854..d177934d 100644 --- a/doc/man7/notmuch-sexp-queries.rst +++ b/doc/man7/notmuch-sexp-queries.rst @@ -41,8 +41,10 @@ subqueries. The empty list matches all messages *term* - Match all messages containing *term*, possibly after stemming - or phase splitting. + Match all messages containing *term*, possibly after + stemming or phase splitting. For discussion of stemming in + notmuch see :any:`notmuch-search-terms(7)`. Stemming only applies + to unquoted terms (basic values) in s-expression queries. ``(`` *field* |q1| |q2| ... |qn| ``)`` Restrict the queries |q1| to |qn| to *field*, and combine with *and* @@ -76,6 +78,10 @@ EXAMPLES ``Wizard`` Match all messages containing the word "wizard", ignoring case. +``added`` + Match all messages containing "added", but also those containing "add", "additional", + "Additional", "adds", etc... via stemming. + .. |q1| replace:: :math:`q_1` .. |q2| replace:: :math:`q_2` .. |qn| replace:: :math:`q_n` diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index 66dbdb41..f031d790 100644 --- a/lib/parse-sexp.cc +++ b/lib/parse-sexp.cc @@ -1,5 +1,4 @@ -#include -#include "notmuch-private.h" +#include "database-private.h" #if HAVE_SFSEXP #include "sexp.h" @@ -18,7 +17,12 @@ _sexp_to_xapian_query (notmuch_database_t *notmuch, const sexp_t *sx, { if (sx->ty == SEXP_VALUE) { - output = Xapian::Query (Xapian::Unicode::tolower (sx->val)); + std::string term = Xapian::Unicode::tolower (sx->val); + Xapian::Stem stem = *(notmuch->stemmer); + if (sx->aty == SEXP_BASIC) + term = "Z" + stem (term); + + output = Xapian::Query (term); return NOTMUCH_STATUS_SUCCESS; } diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index 46cc712c..4e3d755c 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -29,11 +29,14 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "single term in body, stemmed version" -test_subtest_known_broken notmuch search arriv > EXPECTED notmuch search --query=sexp arriv > OUTPUT test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "single term in body, unstemmed version" +notmuch search --query=sexp '"arriv"' > OUTPUT +test_expect_equal_file /dev/null OUTPUT + test_begin_subtest "Unbalanced parens" # A code 1 indicates the error was handled (a crash will return e.g. 139). test_expect_code 1 "notmuch search --query=sexp '('" -- 2.32.0