diff options
| author | David Bremner <david@tethera.net> | 2021-08-24 08:17:27 -0700 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2021-09-04 17:07:19 -0700 |
| commit | 0b98ad5e4ef6b0345f28143243de1170c5c3df54 (patch) | |
| tree | 7b5fd94bffbf78bdd2931f6eb682b3aa5a52e154 /lib/query.cc | |
| parent | bafc307190f694bb3c9dd6dee8af1bae49225529 (diff) | |
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.
Diffstat (limited to 'lib/query.cc')
| -rw-r--r-- | lib/query.cc | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/query.cc b/lib/query.cc index 435f7229..56f90e1c 100644 --- a/lib/query.cc +++ b/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 |
