v6 of regexp searching

David Bremner david at tethera.net
Sun Feb 26 18:34:18 PST 2017


This obsoletes the unmerged patches from

     id:20170217030754.32069-1-david at tethera.net

The first two I plan to merge for 0.24 (barring corrections or objections)

[PATCH 1/4] lib: create field processors from prefix table
[PATCH 2/4] lib: regexp matching in 'subject' and 'from'

The second two could go in for 0.24, or wait.

[PATCH 3/4] lib: add mid: as a synonym for id:
[PATCH 4/4] lib: Add regexp searching for mid: prefix

The big change is a fix for the problem Jani noticed in

    id:87innwhhid.fsf at nikula.org

in the case where field processors are not present.

Interdiff follows.

diff --git a/lib/database-private.h b/lib/database-private.h
index 9fd4102c..ab3d9691 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -154,7 +154,7 @@ typedef enum notmuch_field_flags {
     NOTMUCH_FIELD_NO_FLAGS = 0,
     NOTMUCH_FIELD_EXTERNAL = 1 << 0,
     NOTMUCH_FIELD_PROBABILISTIC = 1 << 1,
-    NOTMUCH_FIELD_PROCESSOR = 1 << 2
+    NOTMUCH_FIELD_PROCESSOR = 1 << 2,
 } notmuch_field_flag_t;
 
 /*
diff --git a/lib/database.cc b/lib/database.cc
index 6e5ea106..09337602 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -293,19 +293,42 @@ prefix_t prefix_table[] = {
 						NOTMUCH_FIELD_PROCESSOR},
 };
 
+static void
+_setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch)
+{
+    if (prefix->flags & NOTMUCH_FIELD_PROBABILISTIC)
+	notmuch->query_parser->add_prefix (prefix->name, prefix->prefix);
+    else
+	notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix);
+}
+
 #if HAVE_XAPIAN_FIELD_PROCESSOR
-static Xapian::FieldProcessor *
-_make_field_processor (const char *name, notmuch_field_flag_t options,
-		       notmuch_database_t *notmuch) {
-    if (STRNCMP_LITERAL (name, "date") == 0)
-	return (new DateFieldProcessor())->release ();
-    else if (STRNCMP_LITERAL(name, "query") == 0)
-	return (new QueryFieldProcessor (*notmuch->query_parser, notmuch))->release ();
+static void
+_setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch)
+{
+    if (prefix->flags & NOTMUCH_FIELD_PROCESSOR) {
+	Xapian::FieldProcessor *fp;
+
+	if (STRNCMP_LITERAL (prefix->name, "date") == 0)
+	    fp = (new DateFieldProcessor())->release ();
+	else if (STRNCMP_LITERAL(prefix->name, "query") == 0)
+	    fp = (new QueryFieldProcessor (*notmuch->query_parser, notmuch))->release ();
 	else
-	return (new RegexpFieldProcessor (name, options, *notmuch->query_parser, notmuch))->release ();
+	    fp = (new RegexpFieldProcessor (prefix->name, prefix->flags,
+					    *notmuch->query_parser, notmuch))->release ();
+
+	/* we treat all field-processor fields as boolean in order to get the raw input */
+	notmuch->query_parser->add_boolean_prefix (prefix->name, fp);
+    } else {
+	_setup_query_field_default (prefix, notmuch);
+    }
 }
 #else
-#define _make_field_processor(name, options, db) NULL
+static inline void
+_setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch)
+{
+    _setup_query_field_default (prefix, notmuch);
+}
 #endif
 
 const char *
@@ -1067,22 +1090,7 @@ notmuch_database_open_verbose (const char *path,
 	for (i = 0; i < ARRAY_SIZE (prefix_table); i++) {
 	    const prefix_t *prefix = &prefix_table[i];
 	    if (prefix->flags & NOTMUCH_FIELD_EXTERNAL) {
-		/* we treat all field-processor fields as boolean in order
-		   to get the raw input */
-		if (HAVE_XAPIAN_FIELD_PROCESSOR &&
-		    (prefix->flags & NOTMUCH_FIELD_PROCESSOR)) {
-		    Xapian::FieldProcessor *fp = _make_field_processor (prefix->name,
-									prefix->flags,
-									notmuch);
-
-		    notmuch->query_parser->add_boolean_prefix (prefix->name, fp);
-		} else if (prefix->flags & NOTMUCH_FIELD_PROBABILISTIC) {
-			notmuch->query_parser->add_prefix (prefix->name,
-							   prefix->prefix);
-		} else {
-		    notmuch->query_parser->add_boolean_prefix (prefix->name,
-							       prefix->prefix);
-		}
+		_setup_query_field (prefix, notmuch);
 	    }
 	}
     } catch (const Xapian::Error &error) {
diff --git a/lib/regexp-fields.h b/lib/regexp-fields.h
index 8a0e72e1..72d12b37 100644
--- a/lib/regexp-fields.h
+++ b/lib/regexp-fields.h
@@ -63,7 +63,7 @@ class RegexpFieldProcessor : public Xapian::FieldProcessor {
  protected:
     Xapian::valueno slot;
     std::string term_prefix;
-    int options;
+    notmuch_field_flag_t options;
     Xapian::QueryParser &parser;
     notmuch_database_t *notmuch;
 
diff --git a/test/T630-regexp-query.sh b/test/T650-regexp-query.sh
similarity index 37%
rename from test/T630-regexp-query.sh
rename to test/T650-regexp-query.sh
index 96bd8746..f0868a15 100755
--- a/test/T630-regexp-query.sh
+++ b/test/T650-regexp-query.sh
@@ -5,7 +5,9 @@ test_description='regular expression searches'
 add_email_corpus
 
 
-if [ $NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR -eq 1 ]; then
+if [ $NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR -eq 0 ]; then
+    test_done
+fi
 
 notmuch search --output=messages from:cworth > cworth.msg-ids
 
@@ -76,6 +78,21 @@ A Xapian exception occurred performing query: Invalid regular expression
 Query string was: from:/unbalanced[/
 EOF
 test_expect_equal_file EXPECTED OUTPUT
-fi
+
+test_begin_subtest "empty mid search"
+notmuch search --output=messages mid:yoom > OUTPUT
+cp /dev/null EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "non-empty mid regex search"
+notmuch search --output=messages mid:/yoom/ > OUTPUT
+test_expect_equal_file cworth.msg-ids OUTPUT
+
+test_begin_subtest "combine regexp mid and subject"
+notmuch search  subject:/-C/ and mid:/y..m/ | notmuch_search_sanitize > OUTPUT
+cat <<EOF > EXPECTED
+thread:XXX   2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
+EOF
+test_expect_equal_file EXPECTED OUTPUT
 
 test_done


More information about the notmuch mailing list