mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-24 11:58:10 +01:00
lib/query: generalize exclude handling to s-expression queries
In fact most of the code path is in common, only the caching of terms in the query needs to be added for s-expression queries.
This commit is contained in:
parent
bafc307190
commit
0b98ad5e4e
2 changed files with 63 additions and 11 deletions
34
lib/query.cc
34
lib/query.cc
|
@ -165,6 +165,19 @@ notmuch_query_create_with_syntax (notmuch_database_t *notmuch,
|
|||
return NOTMUCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
_notmuch_query_cache_terms (notmuch_query_t *query)
|
||||
{
|
||||
/* Xapian doesn't support skip_to on terms from a query since
|
||||
* they are unordered, so cache a copy of all terms in
|
||||
* something searchable.
|
||||
*/
|
||||
|
||||
for (Xapian::TermIterator t = query->xapian_query.get_terms_begin ();
|
||||
t != query->xapian_query.get_terms_end (); ++t)
|
||||
query->terms.insert (*t);
|
||||
}
|
||||
|
||||
static notmuch_status_t
|
||||
_notmuch_query_ensure_parsed_xapian (notmuch_query_t *query)
|
||||
{
|
||||
|
@ -173,15 +186,7 @@ _notmuch_query_ensure_parsed_xapian (notmuch_query_t *query)
|
|||
query->notmuch->query_parser->
|
||||
parse_query (query->query_string, NOTMUCH_QUERY_PARSER_FLAGS);
|
||||
|
||||
/* Xapian doesn't support skip_to on terms from a query since
|
||||
* they are unordered, so cache a copy of all terms in
|
||||
* something searchable.
|
||||
*/
|
||||
|
||||
for (Xapian::TermIterator t = query->xapian_query.get_terms_begin ();
|
||||
t != query->xapian_query.get_terms_end (); ++t)
|
||||
query->terms.insert (*t);
|
||||
|
||||
_notmuch_query_cache_terms (query);
|
||||
query->parsed = true;
|
||||
|
||||
} catch (const Xapian::Error &error) {
|
||||
|
@ -203,11 +208,18 @@ _notmuch_query_ensure_parsed_xapian (notmuch_query_t *query)
|
|||
static notmuch_status_t
|
||||
_notmuch_query_ensure_parsed_sexpr (notmuch_query_t *query)
|
||||
{
|
||||
notmuch_status_t status;
|
||||
|
||||
if (query->parsed)
|
||||
return NOTMUCH_STATUS_SUCCESS;
|
||||
|
||||
return _notmuch_sexp_string_to_xapian_query (query->notmuch, query->query_string,
|
||||
query->xapian_query);
|
||||
status = _notmuch_sexp_string_to_xapian_query (query->notmuch, query->query_string,
|
||||
query->xapian_query);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
_notmuch_query_cache_terms (query);
|
||||
return NOTMUCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static notmuch_status_t
|
||||
|
|
|
@ -525,4 +525,44 @@ notmuch search: Syntax error in query
|
|||
EOF
|
||||
test_expect_equal_file EXPECTED OUTPUT
|
||||
|
||||
test_begin_subtest "Search, exclude \"deleted\" messages from search"
|
||||
notmuch config set search.exclude_tags deleted
|
||||
generate_message '[subject]="Not deleted"'
|
||||
not_deleted_id=$gen_msg_id
|
||||
generate_message '[subject]="Deleted"'
|
||||
notmuch new > /dev/null
|
||||
notmuch tag +deleted id:$gen_msg_id
|
||||
deleted_id=$gen_msg_id
|
||||
output=$(notmuch search --query=sexp '(subject deleted)' | notmuch_search_sanitize)
|
||||
test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)"
|
||||
|
||||
test_begin_subtest "Search, exclude \"deleted\" messages from message search --exclude=false"
|
||||
output=$(notmuch search --query=sexp --exclude=false --output=messages '(subject deleted)' | notmuch_search_sanitize)
|
||||
test_expect_equal "$output" "id:$not_deleted_id
|
||||
id:$deleted_id"
|
||||
|
||||
test_begin_subtest "Search, exclude \"deleted\" messages from search, overridden"
|
||||
notmuch search --query=sexp '(and (subject deleted) (tag deleted))' | notmuch_search_sanitize > OUTPUT
|
||||
cat <<EOF > EXPECTED
|
||||
thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Deleted (deleted inbox unread)
|
||||
EOF
|
||||
test_expect_equal_file EXPECTED OUTPUT
|
||||
|
||||
test_begin_subtest "Search, exclude \"deleted\" messages from threads"
|
||||
add_message '[subject]="Not deleted reply"' '[in-reply-to]="<$gen_msg_id>"'
|
||||
output=$(notmuch search --query=sexp '(subject deleted)' | notmuch_search_sanitize)
|
||||
test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)
|
||||
thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)"
|
||||
|
||||
test_begin_subtest "Search, don't exclude \"deleted\" messages when --exclude=flag specified"
|
||||
output=$(notmuch search --query=sexp --exclude=flag '(subject deleted)' | notmuch_search_sanitize)
|
||||
test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)
|
||||
thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Deleted (deleted inbox unread)"
|
||||
|
||||
test_begin_subtest "Search, don't exclude \"deleted\" messages from search if not configured"
|
||||
notmuch config set search.exclude_tags
|
||||
output=$(notmuch search --query=sexp '(subject deleted)' | notmuch_search_sanitize)
|
||||
test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)
|
||||
thread:XXX 2001-01-05 [2/2] Notmuch Test Suite; Deleted (deleted inbox unread)"
|
||||
|
||||
test_done
|
||||
|
|
Loading…
Reference in a new issue