1 #include "database-private.h"
7 /* _sexp is used for file scope symbols to avoid clashing with
8 * definitions from sexp.h */
10 /* Here we expect the s-expression to be a proper list, with first
11 * element defining and operation, or as a special case the empty
14 static notmuch_status_t
15 _sexp_to_xapian_query (notmuch_database_t *notmuch, const sexp_t *sx,
16 Xapian::Query &output)
19 if (sx->ty == SEXP_VALUE) {
20 std::string term = Xapian::Unicode::tolower (sx->val);
21 Xapian::Stem stem = *(notmuch->stemmer);
22 if (sx->aty == SEXP_BASIC)
23 term = "Z" + stem (term);
25 output = Xapian::Query (term);
26 return NOTMUCH_STATUS_SUCCESS;
31 output = Xapian::Query::MatchAll;
32 return NOTMUCH_STATUS_SUCCESS;
35 if (sx->list->ty == SEXP_VALUE)
36 _notmuch_database_log (notmuch, "unknown prefix '%s'\n", sx->list->val);
38 _notmuch_database_log (notmuch, "unexpected list in field/operation position\n",
41 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
45 _notmuch_sexp_string_to_xapian_query (notmuch_database_t *notmuch, const char *querystr,
46 Xapian::Query &output)
48 const sexp_t *sx = NULL;
49 char *buf = talloc_strdup (notmuch, querystr);
51 sx = parse_sexp (buf, strlen (querystr));
53 _notmuch_database_log (notmuch, "invalid s-expression: '%s'\n", querystr);
54 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
57 return _sexp_to_xapian_query (notmuch, sx, output);