aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2022-04-30 14:26:55 -0300
committerDavid Bremner <david@tethera.net>2022-04-30 14:26:55 -0300
commit97b6a43d46be19b73c2848b29184a93db06ddfe8 (patch)
tree1618e07c4b2c3514946d01dc83e92524a95aae18 /lib
parent4a4ea3234e6bd056aaa4b826765c089e8c884882 (diff)
parenta9b5f8959a20bbce774dec8a65a8b207555e52bd (diff)
Merge tag 'debian/0.36-1' into debian/bullseye-backports
notmuch release 0.36-1 for unstable (sid) [dgit] [dgit distro=debian no-split --quilt=linear]
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.local3
-rw-r--r--lib/database-private.h4
-rw-r--r--lib/prefix.cc5
-rw-r--r--lib/query.cc2
-rw-r--r--lib/regexp-fields.cc3
-rw-r--r--lib/sexp-fp.cc44
-rw-r--r--lib/sexp-fp.h41
7 files changed, 96 insertions, 6 deletions
diff --git a/lib/Makefile.local b/lib/Makefile.local
index 1378a74b..6d67a2a4 100644
--- a/lib/Makefile.local
+++ b/lib/Makefile.local
@@ -64,7 +64,8 @@ libnotmuch_cxx_srcs = \
$(dir)/prefix.cc \
$(dir)/open.cc \
$(dir)/init.cc \
- $(dir)/parse-sexp.cc
+ $(dir)/parse-sexp.cc \
+ $(dir)/sexp-fp.cc
libnotmuch_modules := $(libnotmuch_c_srcs:.c=.o) $(libnotmuch_cxx_srcs:.cc=.o)
diff --git a/lib/database-private.h b/lib/database-private.h
index 657b1aa1..419b9fe6 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -354,10 +354,6 @@ _notmuch_query_string_to_xapian_query (notmuch_database_t *notmuch,
std::string query_string,
Xapian::Query &output,
std::string &msg);
-/* parse-sexp.cc */
-notmuch_status_t
-_notmuch_sexp_string_to_xapian_query (notmuch_database_t *notmuch, const char *querystr,
- Xapian::Query &output);
notmuch_status_t
_notmuch_query_expand (notmuch_database_t *notmuch, const char *field, Xapian::Query subquery,
diff --git a/lib/prefix.cc b/lib/prefix.cc
index 857c05b9..06e2333a 100644
--- a/lib/prefix.cc
+++ b/lib/prefix.cc
@@ -3,6 +3,7 @@
#include "thread-fp.h"
#include "regexp-fields.h"
#include "parse-time-vrp.h"
+#include "sexp-fp.h"
typedef struct {
const char *name;
@@ -60,6 +61,8 @@ prefix_t prefix_table[] = {
NOTMUCH_FIELD_PROCESSOR },
{ "query", NULL, NOTMUCH_FIELD_EXTERNAL |
NOTMUCH_FIELD_PROCESSOR },
+ { "sexp", NULL, NOTMUCH_FIELD_EXTERNAL |
+ NOTMUCH_FIELD_PROCESSOR },
{ "from", "XFROM", NOTMUCH_FIELD_EXTERNAL |
NOTMUCH_FIELD_PROBABILISTIC |
NOTMUCH_FIELD_PROCESSOR },
@@ -138,6 +141,8 @@ _setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch)
fp = (new QueryFieldProcessor (*notmuch->query_parser, notmuch))->release ();
else if (STRNCMP_LITERAL (prefix->name, "thread") == 0)
fp = (new ThreadFieldProcessor (*notmuch->query_parser, notmuch))->release ();
+ else if (STRNCMP_LITERAL (prefix->name, "sexp") == 0)
+ fp = (new SexpFieldProcessor (notmuch))->release ();
else
fp = (new RegexpFieldProcessor (prefix->name, prefix->flags,
*notmuch->query_parser, notmuch))->release ();
diff --git a/lib/query.cc b/lib/query.cc
index b0937fcc..707f6222 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -227,6 +227,7 @@ _notmuch_query_ensure_parsed_xapian (notmuch_query_t *query)
return NOTMUCH_STATUS_SUCCESS;
}
+#if HAVE_SFSEXP
static notmuch_status_t
_notmuch_query_ensure_parsed_sexpr (notmuch_query_t *query)
{
@@ -243,6 +244,7 @@ _notmuch_query_ensure_parsed_sexpr (notmuch_query_t *query)
_notmuch_query_cache_terms (query);
return NOTMUCH_STATUS_SUCCESS;
}
+#endif
static notmuch_status_t
_notmuch_query_ensure_parsed (notmuch_query_t *query)
diff --git a/lib/regexp-fields.cc b/lib/regexp-fields.cc
index 7e9d959c..539915d8 100644
--- a/lib/regexp-fields.cc
+++ b/lib/regexp-fields.cc
@@ -227,7 +227,8 @@ RegexpFieldProcessor::operator() (const std::string & str)
* phrase parsing, when possible */
std::string query_str;
- if (*str.rbegin () != '*' || str.find (' ') != std::string::npos)
+ if ((str.at (0) != '(' || *str.rbegin () != ')') &&
+ (*str.rbegin () != '*' || str.find (' ') != std::string::npos))
query_str = '"' + str + '"';
else
query_str = str;
diff --git a/lib/sexp-fp.cc b/lib/sexp-fp.cc
new file mode 100644
index 00000000..1fdf5225
--- /dev/null
+++ b/lib/sexp-fp.cc
@@ -0,0 +1,44 @@
+/* sexp-fp.cc - "sexp:" field processor glue
+ *
+ * This file is part of notmuch.
+ *
+ * Copyright © 2022 David Bremner
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see https://www.gnu.org/licenses/ .
+ *
+ * Author: David Bremner <david@tethera.net>
+ */
+
+#include "database-private.h"
+#include "sexp-fp.h"
+#include <iostream>
+
+Xapian::Query
+SexpFieldProcessor::operator() (const std::string & query_string)
+{
+ notmuch_status_t status;
+ Xapian::Query output;
+
+#if HAVE_SFSEXP
+ status = _notmuch_sexp_string_to_xapian_query (notmuch, query_string.c_str (), output);
+ if (status) {
+ throw Xapian::QueryParserError ("error parsing " + query_string);
+ }
+#else
+ throw Xapian::QueryParserError ("sexp query parser not available");
+#endif
+
+ return output;
+
+}
diff --git a/lib/sexp-fp.h b/lib/sexp-fp.h
new file mode 100644
index 00000000..341dfa7e
--- /dev/null
+++ b/lib/sexp-fp.h
@@ -0,0 +1,41 @@
+/* sexp-fp.h - sexp field processor glue
+ *
+ * This file is part of notmuch.
+ *
+ * Copyright © 2022 David Bremner
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see https://www.gnu.org/licenses/ .
+ *
+ * Author: David Bremner <david@tethera.net>
+ */
+
+#ifndef NOTMUCH_SEXP_FP_H
+#define NOTMUCH_SEXP_FP_H
+
+#include <xapian.h>
+#include "notmuch.h"
+
+class SexpFieldProcessor : public Xapian::FieldProcessor {
+protected:
+ notmuch_database_t *notmuch;
+
+public:
+ SexpFieldProcessor (notmuch_database_t *notmuch_) : notmuch (notmuch_)
+ {
+ };
+
+ Xapian::Query operator() (const std::string & query_string);
+};
+
+#endif /* NOTMUCH_SEXP_FP_H */