unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* WIP2: index user headers
@ 2019-03-02 15:41 David Bremner
  2019-03-02 15:41 ` [PATCH 1/7] cli/config: refactor _stored_in_db David Bremner
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: David Bremner @ 2019-03-02 15:41 UTC (permalink / raw)
  To: notmuch

This obsoletes [1]
This is getting closer to mergable, but it still needs at least to
sanity check the names of user defined prefixes (see point (a) below).

The main differences from [1] are

(a) xapian prefixes are no longer defined via upper casing, as this is
    locale dependent. The do rely on a ":" separator, hence the need
    for some sanitization.

(b) The caching of user header/prefix information is now done via
    string maps, and used more effectively during indexing.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/7] cli/config: refactor _stored_in_db
  2019-03-02 15:41 WIP2: index user headers David Bremner
@ 2019-03-02 15:41 ` David Bremner
  2019-03-02 15:41 ` [PATCH 2/7] cli/config: support user header index config David Bremner
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2019-03-02 15:41 UTC (permalink / raw)
  To: notmuch

This will make it easier to add other prefixes that are stored in the
database, compared to special casing each one as "query." was.
---
 notmuch-config.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/notmuch-config.c b/notmuch-config.c
index bf77cc9d..1517d0ff 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -821,17 +821,26 @@ _item_split (char *item, char **group, char **key)
 
 #define BUILT_WITH_PREFIX "built_with."
 
+struct config_key {
+    const char *name;
+    bool prefix;
+};
+
 static bool
 _stored_in_db (const char *item)
 {
-    const char * db_configs[] = {
-	"index.decrypt",
+    struct config_key db_configs[] = {
+	{"index.decrypt", false},
+	{"query.", true},
     };
-    if (STRNCMP_LITERAL (item, "query.") == 0)
-	return true;
-    for (size_t i = 0; i < ARRAY_SIZE (db_configs); i++)
-	if (strcmp (item, db_configs[i]) == 0)
+    for (size_t i = 0; i < ARRAY_SIZE (db_configs); i++) {
+	if (db_configs[i].prefix &&
+	    strncmp (item, db_configs[i].name,
+		     strlen(db_configs[i].name)) == 0)
 	    return true;
+	if (strcmp (item, db_configs[i].name) == 0)
+	    return true;
+    }
     return false;
 }
 
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/7] cli/config: support user header index config
  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 ` David Bremner
  2019-03-02 15:41 ` [PATCH 3/7] lib: setup user headers in query parser David Bremner
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2019-03-02 15:41 UTC (permalink / raw)
  To: notmuch

We don't do anything with this configuration information information
yet, but nonetheless add a couple of regression tests to make sure we
don't break standard functionality when we do use the configuration
information.
---
 notmuch-config.c         |  1 +
 test/T730-user-header.sh | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100755 test/T730-user-header.sh

diff --git a/notmuch-config.c b/notmuch-config.c
index 1517d0ff..5112fecd 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -831,6 +831,7 @@ _stored_in_db (const char *item)
 {
     struct config_key db_configs[] = {
 	{"index.decrypt", false},
+	{"index.header.", true},
 	{"query.", true},
     };
     for (size_t i = 0; i < ARRAY_SIZE (db_configs); i++) {
diff --git a/test/T730-user-header.sh b/test/T730-user-header.sh
new file mode 100755
index 00000000..ad32a5b4
--- /dev/null
+++ b/test/T730-user-header.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+test_description='indexing user specified headers'
+. $(dirname "$0")/test-lib.sh || exit 1
+
+test_begin_subtest "error adding user header before initializing DB"
+test_expect_code 1 "notmuch config set index.header.list \"List-Id\""
+
+add_email_corpus
+
+notmuch search '*' | notmuch_search_sanitize > initial-threads
+notmuch search --output=messages '*' > initial-message-ids
+notmuch dump > initial-dump
+
+test_begin_subtest "adding user header"
+test_expect_code 0 "notmuch config set index.header.list \"List-Id\""
+
+test_begin_subtest "adding existing user header"
+test_expect_code 0 "notmuch config set index.header.list \"List-Id\""
+
+test_begin_subtest "retrieve user header"
+output=$(notmuch config get index.header.list)
+test_expect_equal "List-Id" "$output"
+
+test_begin_subtest 'reindex after adding header preserves threads'
+notmuch reindex '*'
+notmuch search '*' | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file initial-threads OUTPUT
+
+test_begin_subtest "List all user headers"
+notmuch config set index.header.spam "X-Spam"
+notmuch config list | grep ^index.header | notmuch_config_sanitize > OUTPUT
+cat <<EOF > EXPECTED
+index.header.list=List-Id
+index.header.spam=X-Spam
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_done
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/7] lib: setup user headers in query parser
  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
  2019-03-02 15:41 ` [PATCH 4/7] lib: cache user prefixes in database object David Bremner
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2019-03-02 15:41 UTC (permalink / raw)
  To: notmuch

These tests will need to be updated if the Xapian
query print/debug format changes.
---
 lib/database.cc          | 35 +++++++++++++++++++++++++++++++++++
 test/T730-user-header.sh | 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()));
diff --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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/7] lib: cache user prefixes in database object
  2019-03-02 15:41 WIP2: index user headers David Bremner
                   ` (2 preceding siblings ...)
  2019-03-02 15:41 ` [PATCH 3/7] lib: setup user headers in query parser David Bremner
@ 2019-03-02 15:41 ` David Bremner
  2019-03-02 15:41 ` [PATCH 5/7] lib: support user prefix names in term generation David Bremner
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2019-03-02 15:41 UTC (permalink / raw)
  To: notmuch

This will be used to avoid needing a database access to resolve a db
prefix from the corresponding UI prefix (e.g. when indexing). Arguably
the setup of the seperate header map does not belong here, since it is
about indexing rather than querying, but we currently don't have any
other indexing setup to do.
---
 lib/database-private.h |  5 +++++
 lib/database.cc        | 39 ++++++++++++++++++++++++++++-----------
 lib/notmuch-private.h  |  9 +++++++++
 lib/thread.cc          |  2 --
 4 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/lib/database-private.h b/lib/database-private.h
index a499b259..57fddada 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -215,6 +215,11 @@ struct _notmuch_database {
     Xapian::ValueRangeProcessor *value_range_processor;
     Xapian::ValueRangeProcessor *date_range_processor;
     Xapian::ValueRangeProcessor *last_mod_range_processor;
+
+    /* XXX it's slightly gross to use two parallel string->string maps
+     * here, but at least they are small */
+    notmuch_string_map_t *user_prefix;
+    notmuch_string_map_t *user_header;
 };
 
 /* Prior to database version 3, features were implied by the database
diff --git a/lib/database.cc b/lib/database.cc
index 4de79f79..6caa1311 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -299,8 +299,6 @@ 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)
 {
@@ -310,29 +308,48 @@ _setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch)
 	notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix);
 }
 
+const char *
+_user_prefix (void *ctx, const char* name)
+{
+    return talloc_asprintf(ctx, "XU%s:", name);
+}
+
 static notmuch_status_t
 _setup_user_query_fields (notmuch_database_t *notmuch)
 {
     notmuch_config_list_t *list;
     notmuch_status_t status;
 
+    notmuch->user_prefix = _notmuch_string_map_create (notmuch);
+    if (notmuch->user_prefix == NULL)
+	return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
+    notmuch->user_header = _notmuch_string_map_create (notmuch);
+    if (notmuch->user_header == NULL)
+	return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
     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
-		};
+	prefix_t query_field;
+
+	const char *key = notmuch_config_list_key (list) +
+	    	    + sizeof (CONFIG_HEADER_PREFIX) - 1;
 
-	const char *key = notmuch_config_list_key (list)
-	    + sizeof (CONFIG_HEADER_PREFIX) - 1;
+	_notmuch_string_map_append (notmuch->user_prefix,
+				    key,
+				    _user_prefix (notmuch, key));
 
-	char *prefix = talloc_asprintf(notmuch, "XU%s:", key);
+	_notmuch_string_map_append (notmuch->user_header,
+				    key,
+				    notmuch_config_list_value (list));
 
-	query_field.name = key;
-	query_field.prefix = prefix;
+	query_field.name = talloc_strdup(notmuch, key);
+	query_field.prefix = _user_prefix(notmuch, key);
+	query_field.flags = NOTMUCH_FIELD_PROBABILISTIC | NOTMUCH_FIELD_EXTERNAL;
 
 	_setup_query_field_default (&query_field, notmuch);
     }
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index df32d39c..1ef26e37 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -181,6 +181,11 @@ typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;
 const char *
 _find_prefix (const char *name);
 
+/* Lookup a prefix value by name, including possibly user defined prefixes
+ */
+const char *
+_notmuch_database_prefix (notmuch_database_t  *notmuch, const char *name);
+
 char *
 _notmuch_message_id_compressed (void *ctx, const char *message_id);
 
@@ -676,6 +681,10 @@ struct _notmuch_indexopts {
     _notmuch_crypto_t crypto;
 };
 
+#define CONFIG_HEADER_PREFIX "index.header."
+
+#define EMPTY_STRING(s) ((s)[0] == '\0')
+
 NOTMUCH_END_DECLS
 
 #ifdef __cplusplus
diff --git a/lib/thread.cc b/lib/thread.cc
index 47c90664..ae830064 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -30,8 +30,6 @@
 #define THREAD_DEBUG(format, ...) do {} while (0) /* ignored */
 #endif
 
-#define EMPTY_STRING(s) ((s)[0] == '\0')
-
 struct _notmuch_thread {
     notmuch_database_t *notmuch;
     char *thread_id;
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/7] lib: support user prefix names in term generation
  2019-03-02 15:41 WIP2: index user headers David Bremner
                   ` (3 preceding siblings ...)
  2019-03-02 15:41 ` [PATCH 4/7] lib: cache user prefixes in database object David Bremner
@ 2019-03-02 15:41 ` David Bremner
  2019-03-02 15:41 ` [PATCH 6/7] lib/database: index user headers David Bremner
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2019-03-02 15:41 UTC (permalink / raw)
  To: notmuch

This should not change the indexing process yet as nothing calls
_notmuch_message_gen_terms with a user prefix name. On the other hand,
it should not break anything either.
---
 lib/database.cc       | 20 ++++++++++++++++++++
 lib/message.cc        |  5 ++++-
 lib/notmuch-private.h |  1 +
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/lib/database.cc b/lib/database.cc
index 6caa1311..19aff0e8 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -405,6 +405,26 @@ _find_prefix (const char *name)
     return "";
 }
 
+/* Like find prefix, but include the possibility of user defined
+ * prefixes specific to this database */
+
+const char *
+_notmuch_database_prefix (notmuch_database_t *notmuch, const char *name)
+{
+    unsigned int i;
+
+    /*XXX TODO: reduce code duplication */
+    for (i = 0; i < ARRAY_SIZE (prefix_table); i++) {
+	if (strcmp (name, prefix_table[i].name) == 0)
+	    return prefix_table[i].prefix;
+    }
+
+    if (notmuch->user_prefix)
+	return _notmuch_string_map_get (notmuch->user_prefix, name);
+
+    return NULL;
+}
+
 static const struct {
     /* NOTMUCH_FEATURE_* value. */
     _notmuch_features value;
diff --git a/lib/message.cc b/lib/message.cc
index 6f2f6345..bbc5ef99 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1434,7 +1434,10 @@ _notmuch_message_gen_terms (notmuch_message_t *message,
     term_gen->set_document (message->doc);
 
     if (prefix_name) {
-	const char *prefix = _find_prefix (prefix_name);
+	const char *prefix = _notmuch_database_prefix (message->notmuch, prefix_name);
+
+	if (prefix == NULL)
+	    return NOTMUCH_PRIVATE_STATUS_BAD_PREFIX;
 
 	term_gen->set_termpos (message->termpos);
 	term_gen->index_text (text, 1, prefix);
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 1ef26e37..cf08411e 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -136,6 +136,7 @@ typedef enum _notmuch_private_status {
     /* Then add our own private values. */
     NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG = NOTMUCH_STATUS_LAST_STATUS,
     NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND,
+    NOTMUCH_PRIVATE_STATUS_BAD_PREFIX,
 
     NOTMUCH_PRIVATE_STATUS_LAST_STATUS
 } notmuch_private_status_t;
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/7] lib/database: index user headers.
  2019-03-02 15:41 WIP2: index user headers David Bremner
                   ` (4 preceding siblings ...)
  2019-03-02 15:41 ` [PATCH 5/7] lib: support user prefix names in term generation David Bremner
@ 2019-03-02 15:41 ` David Bremner
  2019-03-02 15:41 ` [PATCH 7/7] doc: document user header indexing David Bremner
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2019-03-02 15:41 UTC (permalink / raw)
  To: notmuch

There is a O(log(#user headers)) penalty for the second lookup of the
prefix name.
---
 lib/database.cc          |  6 ++++++
 lib/index.cc             | 28 ++++++++++++++++++++++++++++
 lib/notmuch-private.h    |  5 +++++
 test/T730-user-header.sh | 17 +++++++++++++++++
 4 files changed, 56 insertions(+)

diff --git a/lib/database.cc b/lib/database.cc
index 19aff0e8..2219a76a 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -308,6 +308,12 @@ _setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch)
 	notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix);
 }
 
+notmuch_string_map_iterator_t *
+_notmuch_database_user_headers (notmuch_database_t *notmuch)
+{
+    return _notmuch_string_map_iterator_create (notmuch->user_header, "", false);
+}
+
 const char *
 _user_prefix (void *ctx, const char* name)
 {
diff --git a/lib/index.cc b/lib/index.cc
index efd9da4c..ef3369fd 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -595,6 +595,32 @@ _index_encrypted_mime_part (notmuch_message_t *message,
 
 }
 
+static notmuch_status_t
+_notmuch_message_index_user_headers (notmuch_message_t *message, GMimeMessage *mime_message)
+{
+
+    notmuch_database_t *notmuch = notmuch_message_get_database (message);
+    notmuch_string_map_iterator_t *iter = _notmuch_database_user_headers (notmuch);
+
+    for (; _notmuch_string_map_iterator_valid (iter);
+	 _notmuch_string_map_iterator_move_to_next (iter)) {
+
+	const char *prefix_name = _notmuch_string_map_iterator_key (iter);
+
+	const char *header_name = _notmuch_string_map_iterator_value (iter);
+
+	const char *header = g_mime_object_get_header (GMIME_OBJECT (mime_message), header_name);
+	if (header)
+	    _notmuch_message_gen_terms (message, prefix_name, header);
+    }
+
+    if (iter)
+	_notmuch_string_map_iterator_destroy (iter);
+    return NOTMUCH_STATUS_SUCCESS;
+
+}
+
+
 notmuch_status_t
 _notmuch_message_index_file (notmuch_message_t *message,
 			     notmuch_indexopts_t *indexopts,
@@ -625,6 +651,8 @@ _notmuch_message_index_file (notmuch_message_t *message,
     subject = g_mime_message_get_subject (mime_message);
     _notmuch_message_gen_terms (message, "subject", subject);
 
+    status = _notmuch_message_index_user_headers (message, mime_message);
+
     _index_mime_part (message, indexopts, g_mime_message_get_mime_part (mime_message));
 
     return NOTMUCH_STATUS_SUCCESS;
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index cf08411e..e46df9a8 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -652,6 +652,11 @@ _notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator);
 void
 _notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator);
 
+/* Create an iterator for user headers. Destroy with
+ * _notmuch_string_map_iterator_destroy. Actually in database.cc*/
+notmuch_string_map_iterator_t *
+_notmuch_database_user_headers (notmuch_database_t *notmuch);
+
 /* tags.c */
 
 notmuch_tags_t *
diff --git a/test/T730-user-header.sh b/test/T730-user-header.sh
index 1531f1d6..c08985b9 100755
--- a/test/T730-user-header.sh
+++ b/test/T730-user-header.sh
@@ -56,4 +56,21 @@ Query((Tmail AND (XUlist:notmuchmail@1 PHRASE 2 XUlist:org@2)))
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "index user header"
+notmuch config set index.header.list "List-Id"
+notmuch reindex '*'
+notmuch search --output=files list:notmuch | notmuch_search_files_sanitize | sort > OUTPUT
+cat <<EOF > EXPECTED
+MAIL_DIR/bar/baz/05:2,
+MAIL_DIR/bar/baz/23:2,
+MAIL_DIR/bar/baz/24:2,
+MAIL_DIR/bar/cur/20:2,
+MAIL_DIR/bar/new/21:2,
+MAIL_DIR/bar/new/22:2,
+MAIL_DIR/foo/cur/08:2,
+MAIL_DIR/foo/new/03:2,
+MAIL_DIR/new/04:2,
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 7/7] doc: document user header indexing.
  2019-03-02 15:41 WIP2: index user headers David Bremner
                   ` (5 preceding siblings ...)
  2019-03-02 15:41 ` [PATCH 6/7] lib/database: index user headers David Bremner
@ 2019-03-02 15:41 ` David Bremner
  2019-03-02 15:43 ` WIP2: index user headers David Bremner
  2019-03-03 14:56 ` David Bremner
  8 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2019-03-02 15:41 UTC (permalink / raw)
  To: notmuch

It's a bit odd that the primary documentation is in notmuch-config,
but it is consistent with the "query:" prefix.
---
 doc/man1/notmuch-config.rst       | 8 ++++++++
 doc/man7/notmuch-search-terms.rst | 3 +++
 2 files changed, 11 insertions(+)

diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index 89909808..b91cbfd3 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -195,6 +195,14 @@ The available configuration items are described below.
 
     Default: ``auto``.
 
+**index.header.<prefix>** **[STORED IN DATABASE]**
+    Define the query prefix <prefix>, based on a mail header. For
+    example ``index.header.list=List-Id`` will add a probabilistic
+    prefix ``list:`` that searches the ``List-Id`` field. Adding a
+    prefix with same name as a predefined prefix is not supported. See
+    **notmuch-search-terms(7)** for a list of existing prefixes, and
+    an explanation of probabilistic prefixes.
+
 **built_with.<name>**
     Compile time feature <name>. Current possibilities include
     "compact" (see **notmuch-compact(1)**) and "field_processor" (see
diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst
index f7a39ceb..36ba804b 100644
--- a/doc/man7/notmuch-search-terms.rst
+++ b/doc/man7/notmuch-search-terms.rst
@@ -166,6 +166,9 @@ property:<key>=<value>
     can be present on a given message with several different values.
     See **notmuch-properties(7)** for more details.
 
+User defined prefixes are also supported, see **notmuch-config(1)** for
+details.
+
 Operators
 ---------
 
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: WIP2: index user headers
  2019-03-02 15:41 WIP2: index user headers David Bremner
                   ` (6 preceding siblings ...)
  2019-03-02 15:41 ` [PATCH 7/7] doc: document user header indexing David Bremner
@ 2019-03-02 15:43 ` David Bremner
  2019-03-03 14:56 ` David Bremner
  8 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2019-03-02 15:43 UTC (permalink / raw)
  To: notmuch

David Bremner <david@tethera.net> writes:

> This obsoletes [1]
> This is getting closer to mergable, but it still needs at least to
> sanity check the names of user defined prefixes (see point (a) below).
>
> The main differences from [1] are

[1] is of course id:20181117140901.1870-1-david@tethera.net

>
> (a) xapian prefixes are no longer defined via upper casing, as this is
>     locale dependent. The do rely on a ":" separator, hence the need
>     for some sanitization.
>
> (b) The caching of user header/prefix information is now done via
>     string maps, and used more effectively during indexing.
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: WIP2: index user headers
  2019-03-02 15:41 WIP2: index user headers David Bremner
                   ` (7 preceding siblings ...)
  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
  8 siblings, 1 reply; 11+ messages in thread
From: David Bremner @ 2019-03-03 14:56 UTC (permalink / raw)
  To: notmuch

David Bremner <david@tethera.net> writes:

> This obsoletes [1]
> This is getting closer to mergable, but it still needs at least to
> sanity check the names of user defined prefixes (see point (a) below).
>
> The main differences from [1] are
>
> (a) xapian prefixes are no longer defined via upper casing, as this is
>     locale dependent. The do rely on a ":" separator, hence the need
>     for some sanitization.
>
> (b) The caching of user header/prefix information is now done via
>     string maps, and used more effectively during indexing.

I had another thought about user prefixes. I wonder if they should all
be forcibly prefixed with something that prevents collisions, to prevent
later pain if we add an "official" prefix with the same name. A quick
tests suggest it would work to use something like _

so

        notmuch search --output=files _list:notmuch

works. It's a bit ugly, I'll have to play with other options; the main
question is whether we think prefixing is needed / worth-it.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: WIP2: index user headers
  2019-03-03 14:56 ` David Bremner
@ 2019-03-04  1:54   ` David Bremner
  0 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2019-03-04  1:54 UTC (permalink / raw)
  To: notmuch

David Bremner <david@tethera.net> writes:

> I had another thought about user prefixes. I wonder if they should all
> be forcibly prefixed with something that prevents collisions, to prevent
> later pain if we add an "official" prefix with the same name. A quick
> tests suggest it would work to use something like _
>
> so
>
>         notmuch search --output=files _list:notmuch
>
> works. It's a bit ugly, I'll have to play with other options; the main
> question is whether we think prefixing is needed / worth-it.

I played with the query parser a bit, and the only idea I found so far
is to reserve prefixes starting with lower case ASCII for notmuch, and
allow users to use anything else.

d

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-03-04  1:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 3/7] lib: setup user headers in query parser David Bremner
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

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).