]> git.notmuchmail.org Git - notmuch/commitdiff
lib: do not phrase parse prefixed bracketed subexpressions
authorDavid Bremner <david@tethera.net>
Fri, 25 Feb 2022 02:41:03 +0000 (22:41 -0400)
committerDavid Bremner <david@tethera.net>
Sat, 19 Mar 2022 10:27:29 +0000 (07:27 -0300)
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
lib/regexp-fields.cc
test/T650-regexp-query.sh

index e80cc7d0b3faa76790a38a5e495d3f2b4516e896..f8ad1edb2c7ab92122c45c59d11a2b845f1e47d2 100644 (file)
@@ -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
 
index 7e9d959c9b0bc15ffc5b10a9754246750384e668..539915d892f9529d3d011dfa7611bb37aba718d2 100644 (file)
@@ -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;
index 4ee6b1713747bf59cecc6f301061dcb787b8be7a..a9844501edf4b60f7c2652838a26ef7926363a4c 100755 (executable)
@@ -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