[PATCH 3.5/8] Query parser tests for wildcard queries.
Austin Clements
amdragon at MIT.EDU
Thu Jan 20 22:40:03 PST 2011
Since wildcard queries require a database, qparser-test can now open a
database.
---
This is intended to be applied after patch 3/5 in this series,
id:1295165458-9573-4-git-send-email-amdragon at mit.edu
test/qparser | 7 +++++++
test/qparser-test.cc | 25 ++++++++++++++++++++++++-
test/qparser.expected-output/wildcards | 20 ++++++++++++++++++++
3 files changed, 51 insertions(+), 1 deletions(-)
create mode 100644 test/qparser.expected-output/wildcards
diff --git a/test/qparser b/test/qparser
index 7ed5c97..d77e2b2 100755
--- a/test/qparser
+++ b/test/qparser
@@ -34,4 +34,11 @@ output=$(../qparser-test < $EXPECTED/probs)
expected=$(cat $EXPECTED/probs)
test_expect_equal "$output" "$expected"
+add_message '[body]="Peter Piper picked a peck of pickled peppers"'
+
+test_begin_subtest "Wildcards"
+output=$(../qparser-test -d < $EXPECTED/wildcards)
+expected=$(cat $EXPECTED/wildcards)
+test_expect_equal "$output" "$expected"
+
test_done
diff --git a/test/qparser-test.cc b/test/qparser-test.cc
index 01d6bae..ae6c8b9 100644
--- a/test/qparser-test.cc
+++ b/test/qparser-test.cc
@@ -42,6 +42,7 @@ extern "C" {
#include "../notmuch-client.h"
}
+static notmuch_database_t *notmuch;
static _notmuch_qparser_t *qparser;
static Xapian::QueryParser xqparser;
@@ -98,7 +99,7 @@ test_one (void *ctx, const char *query_str)
static _notmuch_qparser_t *
create_qparser (void *ctx)
{
- _notmuch_qparser_t *qparser = _notmuch_qparser_create (ctx, NULL);
+ _notmuch_qparser_t *qparser = _notmuch_qparser_create (ctx, notmuch);
_notmuch_qparser_add_db_prefix (qparser, "prob", "P", FALSE);
_notmuch_qparser_add_db_prefix (qparser, "lit", "L", TRUE);
_notmuch_qparser_add_db_prefix (qparser, "tag", "K", TRUE);
@@ -109,6 +110,8 @@ static Xapian::QueryParser
create_xapian_qparser (void)
{
Xapian::QueryParser xq;
+ if (notmuch)
+ xq.set_database (*notmuch->xapian_db);
xq.set_default_op (Xapian::Query::OP_AND);
xq.add_prefix ("prob", "P");
xq.add_boolean_prefix ("lit", "L");
@@ -120,9 +123,27 @@ int
main (int argc, char **argv)
{
void *ctx;
+ notmuch_config_t *config;
ctx = talloc_new (NULL);
+ if (argc > 1 && strcmp(argv[1], "-d") == 0) {
+ argc--;
+ argv++;
+
+ /* Open the database */
+ config = notmuch_config_open (ctx, NULL, NULL);
+ if (config == NULL)
+ return 1;
+
+ notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_ONLY);
+ if (notmuch == NULL)
+ return 1;
+ } else {
+ notmuch = NULL;
+ }
+
qparser = create_qparser (ctx);
xqparser = create_xapian_qparser ();
@@ -149,5 +170,7 @@ main (int argc, char **argv)
}
}
+ if (notmuch)
+ notmuch_database_close (notmuch);
return 0;
}
diff --git a/test/qparser.expected-output/wildcards b/test/qparser.expected-output/wildcards
new file mode 100644
index 0000000..6f62829
--- /dev/null
+++ b/test/qparser.expected-output/wildcards
@@ -0,0 +1,20 @@
+# Basic wildcard expansion
+p* AND x
+[lex] "p"* AND "x"
+[parse] (AND "p"* "x")
+[gen] ((peck:(pos=1) SYNONYM peppers:(pos=1) SYNONYM peter:(pos=1) SYNONYM picked:(pos=1) SYNONYM pickled:(pos=1) SYNONYM piper:(pos=1)) AND x:(pos=2))
+
+# Incompatible; Xapian considers this a syntax error
+*
+[lex] ""*
+[parse] ""*
+[gen] <alldocuments>
+[xapian]
+
+# Wildcard that matches nothing. Xapian handles this differently
+# but equivalently.
+nosuchterm* AND x
+[lex] "nosuchterm"* AND "x"
+[parse] (AND "nosuchterm"* "x")
+[gen] (nosuchterm AND x:(pos=1))
+[xapian]
--
1.7.2.3
More information about the notmuch
mailing list