X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fparse-sexp.cc;fp=lib%2Fparse-sexp.cc;h=0192bda96cb5cea5cf23e363595592f40c874b70;hp=ffb00148393659b8a548c7796285a791b89688a4;hb=bafc307190f694bb3c9dd6dee8af1bae49225529;hpb=0ca4ad2670b22e975a018f9f662ea3a762840583 diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index ffb00148..0192bda9 100644 --- a/lib/parse-sexp.cc +++ b/lib/parse-sexp.cc @@ -164,6 +164,22 @@ _sexp_parse_wildcard (notmuch_database_t *notmuch, return NOTMUCH_STATUS_SUCCESS; } +static notmuch_status_t +_sexp_parse_one_term (notmuch_database_t *notmuch, std::string term_prefix, const sexp_t *sx, + Xapian::Query &output) +{ + Xapian::Stem stem = *(notmuch->stemmer); + + if (sx->aty == SEXP_BASIC && unicode_word_utf8 (sx->val)) { + std::string term = Xapian::Unicode::tolower (sx->val); + + output = Xapian::Query ("Z" + term_prefix + stem (term)); + return NOTMUCH_STATUS_SUCCESS; + } else { + return _sexp_parse_phrase (term_prefix, sx->val, output); + } + +} /* Here we expect the s-expression to be a proper list, with first * element defining and operation, or as a special case the empty * list */ @@ -185,11 +201,23 @@ _sexp_to_xapian_query (notmuch_database_t *notmuch, const _sexp_prefix_t *parent output = Xapian::Query (term_prefix + sx->val); return NOTMUCH_STATUS_SUCCESS; } - if (sx->aty == SEXP_BASIC && unicode_word_utf8 (sx->val)) { - output = Xapian::Query ("Z" + term_prefix + stem (term)); - return NOTMUCH_STATUS_SUCCESS; + if (parent) { + return _sexp_parse_one_term (notmuch, term_prefix, sx, output); } else { - return _sexp_parse_phrase (term_prefix, sx->val, output); + Xapian::Query accumulator; + for (_sexp_prefix_t *prefix = prefixes; prefix->name; prefix++) { + if (prefix->flags & SEXP_FLAG_FIELD) { + notmuch_status_t status; + Xapian::Query subquery; + term_prefix = _find_prefix (prefix->name); + status = _sexp_parse_one_term (notmuch, term_prefix, sx, subquery); + if (status) + return status; + accumulator = Xapian::Query (Xapian::Query::OP_OR, accumulator, subquery); + } + } + output = accumulator; + return NOTMUCH_STATUS_SUCCESS; } }