From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 3/7] lib: setup user headers in query parser
Date: Sat, 2 Mar 2019 11:41:29 -0400 [thread overview]
Message-ID: <20190302154133.25642-4-david@tethera.net> (raw)
In-Reply-To: <20190302154133.25642-1-david@tethera.net>
These tests will need to be updated if the Xapian
query print/debug format changes.
---
lib/database.cc | 35 +++++++++++++++++++++++++++++++++++
| 21 +++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/lib/database.cc b/lib/database.cc
index 9cf8062c..4de79f79 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -299,6 +299,8 @@ prefix_t prefix_table[] = {
NOTMUCH_FIELD_PROCESSOR},
};
+#define CONFIG_HEADER_PREFIX "index.header."
+
static void
_setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch)
{
@@ -308,6 +310,38 @@ _setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch)
notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix);
}
+static notmuch_status_t
+_setup_user_query_fields (notmuch_database_t *notmuch)
+{
+ notmuch_config_list_t *list;
+ notmuch_status_t status;
+
+ status = notmuch_database_get_config_list (notmuch, CONFIG_HEADER_PREFIX, &list);
+ if (status)
+ return status;
+ for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
+
+ prefix_t query_field { .name = NULL, .prefix = NULL,
+ .flags = NOTMUCH_FIELD_PROBABILISTIC |
+ NOTMUCH_FIELD_EXTERNAL
+ };
+
+ const char *key = notmuch_config_list_key (list)
+ + sizeof (CONFIG_HEADER_PREFIX) - 1;
+
+ char *prefix = talloc_asprintf(notmuch, "XU%s:", key);
+
+ query_field.name = key;
+ query_field.prefix = prefix;
+
+ _setup_query_field_default (&query_field, notmuch);
+ }
+
+ notmuch_config_list_destroy (list);
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
#if HAVE_XAPIAN_FIELD_PROCESSOR
static void
_setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch)
@@ -965,6 +999,7 @@ notmuch_database_open_verbose (const char *path,
_setup_query_field (prefix, notmuch);
}
}
+ status = _setup_user_query_fields (notmuch);
} catch (const Xapian::Error &error) {
IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n",
error.get_msg().c_str()));
--git a/test/T730-user-header.sh b/test/T730-user-header.sh
index ad32a5b4..1531f1d6 100755
--- a/test/T730-user-header.sh
+++ b/test/T730-user-header.sh
@@ -35,4 +35,25 @@ index.header.spam=X-Spam
EOF
test_expect_equal_file EXPECTED OUTPUT
+test_begin_subtest "parse user prefix"
+NOTMUCH_DEBUG_QUERY=t notmuch count 'list:"notmuch"' 2>&1 | grep Tmail >OUTPUT
+cat <<EOF > EXPECTED
+Query((Tmail AND XUlist:notmuch@1))
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "parse user prefix, stemmed"
+NOTMUCH_DEBUG_QUERY=t notmuch count 'list:notmuch' 2>&1 | grep Tmail >OUTPUT
+cat <<EOF > EXPECTED
+Query((Tmail AND ZXUlist:notmuch@1))
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "parse user prefix, phrase"
+NOTMUCH_DEBUG_QUERY=t notmuch count 'list:notmuchmail.org' 2>&1 | grep Tmail >OUTPUT
+cat <<EOF > EXPECTED
+Query((Tmail AND (XUlist:notmuchmail@1 PHRASE 2 XUlist:org@2)))
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
test_done
--
2.20.1
next prev parent reply other threads:[~2019-03-02 15:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-02 15:41 WIP2: index user headers David Bremner
2019-03-02 15:41 ` [PATCH 1/7] cli/config: refactor _stored_in_db David Bremner
2019-03-02 15:41 ` [PATCH 2/7] cli/config: support user header index config David Bremner
2019-03-02 15:41 ` David Bremner [this message]
2019-03-02 15:41 ` [PATCH 4/7] lib: cache user prefixes in database object David Bremner
2019-03-02 15:41 ` [PATCH 5/7] lib: support user prefix names in term generation David Bremner
2019-03-02 15:41 ` [PATCH 6/7] lib/database: index user headers David Bremner
2019-03-02 15:41 ` [PATCH 7/7] doc: document user header indexing David Bremner
2019-03-02 15:43 ` WIP2: index user headers David Bremner
2019-03-03 14:56 ` David Bremner
2019-03-04 1:54 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190302154133.25642-4-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).