2 #include "notmuch-private.h"
8 /* _sexp is used for file scope symbols to avoid clashing with
9 * definitions from sexp.h */
11 /* Here we expect the s-expression to be a proper list, with first
12 * element defining and operation, or as a special case the empty
15 static notmuch_status_t
16 _sexp_to_xapian_query (notmuch_database_t *notmuch, const sexp_t *sx,
17 Xapian::Query &output)
20 if (sx->ty == SEXP_VALUE) {
21 output = Xapian::Query (Xapian::Unicode::tolower (sx->val));
22 return NOTMUCH_STATUS_SUCCESS;
27 output = Xapian::Query::MatchAll;
28 return NOTMUCH_STATUS_SUCCESS;
31 if (sx->list->ty == SEXP_VALUE)
32 _notmuch_database_log (notmuch, "unknown prefix '%s'\n", sx->list->val);
34 _notmuch_database_log (notmuch, "unexpected list in field/operation position\n",
37 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
41 _notmuch_sexp_string_to_xapian_query (notmuch_database_t *notmuch, const char *querystr,
42 Xapian::Query &output)
44 const sexp_t *sx = NULL;
45 char *buf = talloc_strdup (notmuch, querystr);
47 sx = parse_sexp (buf, strlen (querystr));
49 _notmuch_database_log (notmuch, "invalid s-expression: '%s'\n", querystr);
50 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
53 return _sexp_to_xapian_query (notmuch, sx, output);