aboutsummaryrefslogtreecommitdiff
path: root/lib/parse-sexp.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2021-08-24 08:17:26 -0700
committerDavid Bremner <david@tethera.net>2021-09-04 17:07:19 -0700
commitbafc307190f694bb3c9dd6dee8af1bae49225529 (patch)
treef73397cc74fa46a662ecab4c5037fb3f48ed6139 /lib/parse-sexp.cc
parent0ca4ad2670b22e975a018f9f662ea3a762840583 (diff)
lib/parse-sexp: handle unprefixed terms.
This is equivalent to adding the same field name "" for multiple prefixes in the Xapian query parser, but we have to explicitely construct the resulting query.
Diffstat (limited to 'lib/parse-sexp.cc')
-rw-r--r--lib/parse-sexp.cc36
1 files changed, 32 insertions, 4 deletions
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;
}
}