X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fquery.cc;h=56f90e1ce1480d6a14de1e594565be1ff31144c6;hb=5cb452c325e1f69e43dca610f48b9396cba9c039;hp=a3fe379342959d0ba5a55f756893d8f348a29cff;hpb=c4f2f33a50643b41e6dbf0519c563ae7db48beab;p=notmuch diff --git a/lib/query.cc b/lib/query.cc index a3fe3793..56f90e1c 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -23,10 +23,6 @@ #include /* GHashTable, GPtrArray */ -#if HAVE_SFSEXP -#include "sexp.h" -#endif - struct _notmuch_query { notmuch_database_t *notmuch; const char *query_string; @@ -169,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) { @@ -177,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) { @@ -207,10 +208,17 @@ _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; - query->xapian_query = Xapian::Query::MatchAll; + 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; }