From: David Bremner <david@tethera.net>
To: Sean Whitton <spwhitton@spwhitton.name>, notmuch@notmuchmail.org
Subject: [PATCH 2/2] lib: do not phrase parse prefixed bracketed subexpressions
Date: Thu, 24 Feb 2022 22:41:03 -0400 [thread overview]
Message-ID: <20220225024103.1026629-3-david@tethera.net> (raw)
In-Reply-To: <20220225024103.1026629-1-david@tethera.net>
Since Xapian does not preserve quotes when passing the subquery to a
field processor, we have to make a guess as to what the user
intended. Here the added assumption is that a string surrounded by
parens is not intended to be a phrase.
---
doc/man7/notmuch-search-terms.rst | 6 ++++--
lib/regexp-fields.cc | 3 ++-
test/T650-regexp-query.sh | 13 ++++++++++---
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst
index e80cc7d0..f8ad1edb 100644
--- a/doc/man7/notmuch-search-terms.rst
+++ b/doc/man7/notmuch-search-terms.rst
@@ -275,11 +275,13 @@ the same phrase.
- a.list.of.words
Both parenthesised lists of terms and quoted phrases are ok with
-probabilistic prefixes such as **to:**, **from:**, and **subject:**. In particular
+probabilistic prefixes such as **to:**, **from:**, and **subject:**.
+For prefixes supporting regex search, the parenthesised list should be
+quoted. In particular
::
- subject:(pizza free)
+ subject:"(pizza free)"
is equivalent to
diff --git a/lib/regexp-fields.cc b/lib/regexp-fields.cc
index 7e9d959c..539915d8 100644
--- a/lib/regexp-fields.cc
+++ b/lib/regexp-fields.cc
@@ -227,7 +227,8 @@ RegexpFieldProcessor::operator() (const std::string & str)
* phrase parsing, when possible */
std::string query_str;
- if (*str.rbegin () != '*' || str.find (' ') != std::string::npos)
+ if ((str.at (0) != '(' || *str.rbegin () != ')') &&
+ (*str.rbegin () != '*' || str.find (' ') != std::string::npos))
query_str = '"' + str + '"';
else
query_str = str;
diff --git a/test/T650-regexp-query.sh b/test/T650-regexp-query.sh
index 4ee6b171..a9844501 100755
--- a/test/T650-regexp-query.sh
+++ b/test/T650-regexp-query.sh
@@ -66,23 +66,30 @@ EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "bracketed subject search (with dquotes)"
-test_subtest_known_broken
notmuch search subject:notmuch and subject:show > EXPECTED
notmuch search 'subject:"(show notmuch)"' > OUTPUT
test_expect_equal_file_nonempty EXPECTED OUTPUT
test_begin_subtest "bracketed subject search (with dquotes and operator 'or')"
-test_subtest_known_broken
notmuch search subject:notmuch or subject:show > EXPECTED
notmuch search 'subject:"(notmuch or show)"' > OUTPUT
test_expect_equal_file_nonempty EXPECTED OUTPUT
test_begin_subtest "bracketed subject search (with dquotes and operator 'and')"
-test_subtest_known_broken
notmuch search subject:notmuch and subject:show > EXPECTED
notmuch search 'subject:"(notmuch and show)"' > OUTPUT
test_expect_equal_file_nonempty EXPECTED OUTPUT
+test_begin_subtest "bracketed subject search (with phrase, operator 'or')"
+notmuch search 'subject:"mailing list"' or subject:FreeBSD > EXPECTED
+notmuch search 'subject:"(""mailing list"" or FreeBSD)"' > OUTPUT
+test_expect_equal_file_nonempty EXPECTED OUTPUT
+
+test_begin_subtest "bracketed subject search (with phrase, operator 'and')"
+notmuch search search 'subject:"notmuch show"' and subject:commands > EXPECTED
+notmuch search 'subject:"(""notmuch show"" and commands)"' > OUTPUT
+test_expect_equal_file_nonempty EXPECTED OUTPUT
+
test_begin_subtest "xapian wildcard search for from:"
notmuch search --output=messages 'from:cwo*' > OUTPUT
test_expect_equal_file cworth.msg-ids OUTPUT
--
2.34.1
prev parent reply other threads:[~2022-02-25 2:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 15:20 Parenthesised query breaks query it is embedded in Sean Whitton
2022-02-25 2:41 ` fix for parsing bracketed expression David Bremner
2022-02-25 2:41 ` [PATCH 1/2] test: known broken tests for bracketed terms in subject David Bremner
2022-03-19 10:38 ` David Bremner
2022-03-20 16:29 ` Sean Whitton
2022-02-25 2:41 ` David Bremner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220225024103.1026629-3-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
--cc=spwhitton@spwhitton.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).