lib: do not phrase parse prefixed bracketed subexpressions

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.
This commit is contained in:
David Bremner 2022-02-24 22:41:03 -04:00
parent c9ed87f39f
commit 8ed6a172b3
3 changed files with 16 additions and 6 deletions

View file

@ -275,11 +275,13 @@ the same phrase.
- a.list.of.words - a.list.of.words
Both parenthesised lists of terms and quoted phrases are ok with 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 is equivalent to

View file

@ -227,7 +227,8 @@ RegexpFieldProcessor::operator() (const std::string & str)
* phrase parsing, when possible */ * phrase parsing, when possible */
std::string query_str; 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 + '"'; query_str = '"' + str + '"';
else else
query_str = str; query_str = str;

View file

@ -66,23 +66,30 @@ EOF
test_expect_equal_file EXPECTED OUTPUT test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "bracketed subject search (with dquotes)" test_begin_subtest "bracketed subject search (with dquotes)"
test_subtest_known_broken
notmuch search subject:notmuch and subject:show > EXPECTED notmuch search subject:notmuch and subject:show > EXPECTED
notmuch search 'subject:"(show notmuch)"' > OUTPUT notmuch search 'subject:"(show notmuch)"' > OUTPUT
test_expect_equal_file_nonempty EXPECTED OUTPUT test_expect_equal_file_nonempty EXPECTED OUTPUT
test_begin_subtest "bracketed subject search (with dquotes and operator 'or')" 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 subject:show > EXPECTED
notmuch search 'subject:"(notmuch or show)"' > OUTPUT notmuch search 'subject:"(notmuch or show)"' > OUTPUT
test_expect_equal_file_nonempty EXPECTED OUTPUT test_expect_equal_file_nonempty EXPECTED OUTPUT
test_begin_subtest "bracketed subject search (with dquotes and operator 'and')" 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 subject:show > EXPECTED
notmuch search 'subject:"(notmuch and show)"' > OUTPUT notmuch search 'subject:"(notmuch and show)"' > OUTPUT
test_expect_equal_file_nonempty EXPECTED 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:" test_begin_subtest "xapian wildcard search for from:"
notmuch search --output=messages 'from:cwo*' > OUTPUT notmuch search --output=messages 'from:cwo*' > OUTPUT
test_expect_equal_file cworth.msg-ids OUTPUT test_expect_equal_file cworth.msg-ids OUTPUT