]> git.cworth.org Git - notmuch/commitdiff
WIP: enable new extended wildcard support in Xapian 2.0 feature/wildcard
authorDavid Bremner <david@tethera.net>
Sun, 8 Mar 2026 00:15:15 +0000 (09:15 +0900)
committerDavid Bremner <david@tethera.net>
Fri, 13 Mar 2026 22:35:00 +0000 (07:35 +0900)
As can be seen from the included tests, this currently only works for
fields without other field processors (in particular regex supporting
fields seem to break it).

lib/database-private.h
test/T870-extended-wildcard.sh [new file with mode: 0755]

index 2959b3ac5029ca65b6d5467a283941ed0f47d8a2..776ebc48601e2a7f068509d2a50f3106160a3403 100644 (file)
@@ -185,11 +185,17 @@ operator& (notmuch_field_flag_t a, notmuch_field_flag_t b)
        static_cast<unsigned>(a) & static_cast<unsigned>(b));
 }
 
+#ifdef HAVE_XAPIAN_WILDCARD_GLOB
+#define NOTMUCH_XAPIAN_WILDCARD_FLAG Xapian::QueryParser::FLAG_WILDCARD_GLOB
+#else
+#define NOTMUCH_XAPIAN_WILDCARD_FLAG Xapian::QueryParser::FLAG_WILDCARD
+#endif
+
 #define NOTMUCH_QUERY_PARSER_FLAGS (Xapian::QueryParser::FLAG_BOOLEAN | \
                                    Xapian::QueryParser::FLAG_PHRASE | \
                                    Xapian::QueryParser::FLAG_LOVEHATE | \
                                    Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE | \
-                                   Xapian::QueryParser::FLAG_WILDCARD | \
+                                   NOTMUCH_XAPIAN_WILDCARD_FLAG | \
                                    Xapian::QueryParser::FLAG_PURE_NOT)
 
 /*
diff --git a/test/T870-extended-wildcard.sh b/test/T870-extended-wildcard.sh
new file mode 100755 (executable)
index 0000000..16621ec
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+test_description='extended wildcard support in Xapian query parser'
+. $(dirname "$0")/test-lib.sh || exit 1
+
+if [ "${NOTMUCH_HAVE_XAPIAN_WILDCARD_GLOB-0}" != "1" ]; then
+    printf "Skipping due to missing extended wildcard support\n"
+    test_done
+fi
+
+add_email_corpus
+
+count=0
+for field in "any" 'body' 'from' 'subject' 'to' ; do
+    for glob in 'm?tch' '?a?ch' 'm?tc?' '*atch' 'mat*' '*at*'; do
+       test_begin_subtest "field $field, glob $glob"
+       case $field in
+           from|subject)
+               test_subtest_known_broken
+               ;;
+       esac
+       count=$((count + 1))
+       cookie="match$count"
+       reversecookie="${count}match"
+       queryglob="$glob$count"
+       if [ $field == 'any' ]; then
+           msgfield='body'
+           queryprefix=''
+       else
+           msgfield=$field
+           queryprefix="$field:"
+       fi
+       reversequeryglob="$count$glob"
+       add_message "[$msgfield]=$cookie"
+       add_message "[$msgfield]=$reversecookie"
+       output=$(notmuch count "$queryprefix$queryglob")
+       output="$output $(notmuch count "$queryprefix$reversequeryglob")"
+       test_expect_equal "$output" "1 1"
+    done
+done
+test_done