[PATCH 2.5/8] Query parser tests for NEAR and ADJ operators.
Austin Clements
amdragon at MIT.EDU
Thu Jan 20 22:39:02 PST 2011
---
This is intended to be applied after patch 2/8 in this series,
id:1295165458-9573-3-git-send-email-amdragon at mit.edu
test/qparser | 5 ++
test/qparser.expected-output/near-and-adj | 83 +++++++++++++++++++++++++++++
test/qparser.expected-output/operators | 12 ++++
test/qparser.expected-output/probs | 6 ++
4 files changed, 106 insertions(+), 0 deletions(-)
create mode 100644 test/qparser.expected-output/near-and-adj
diff --git a/test/qparser b/test/qparser
index 0e7b022..7ed5c97 100755
--- a/test/qparser
+++ b/test/qparser
@@ -24,6 +24,11 @@ output=$(../qparser-test < $EXPECTED/operators)
expected=$(cat $EXPECTED/operators)
test_expect_equal "$output" "$expected"
+test_begin_subtest "Near and adj"
+output=$(../qparser-test < $EXPECTED/near-and-adj)
+expected=$(cat $EXPECTED/near-and-adj)
+test_expect_equal "$output" "$expected"
+
test_begin_subtest "Probs"
output=$(../qparser-test < $EXPECTED/probs)
expected=$(cat $EXPECTED/probs)
diff --git a/test/qparser.expected-output/near-and-adj b/test/qparser.expected-output/near-and-adj
new file mode 100644
index 0000000..0da4689
--- /dev/null
+++ b/test/qparser.expected-output/near-and-adj
@@ -0,0 +1,83 @@
+x near y
+[lex] "x" NEAR "y"
+[parse] (NEAR "x" (NEAR "y"))
+[gen] (x:(pos=1) NEAR 11 y:(pos=2))
+
+x near y near z
+[lex] "x" NEAR "y" NEAR "z"
+[parse] (NEAR "x" (NEAR "y" (NEAR "z")))
+[gen] (x:(pos=1) NEAR 12 y:(pos=2) NEAR 12 z:(pos=3))
+
+x near/2 y
+[lex] "x" NEAR/2 "y"
+[parse] (NEAR "x" (NEAR/2 "y"))
+[gen] (x:(pos=1) NEAR 3 y:(pos=2))
+
+x near/2 y near z
+[lex] "x" NEAR/2 "y" NEAR "z"
+[parse] (NEAR "x" (NEAR/2 "y" (NEAR "z")))
+[gen] (x:(pos=1) NEAR 4 y:(pos=2) NEAR 4 z:(pos=3))
+
+x near y near/2 z
+[lex] "x" NEAR "y" NEAR/2 "z"
+[parse] (NEAR "x" (NEAR "y" (NEAR/2 "z")))
+[gen] (x:(pos=1) NEAR 4 y:(pos=2) NEAR 4 z:(pos=3))
+
+x near/0 y
+[lex] "x" "near/0" "y"
+[parse] (AND (AND "x" "near/0") "y")
+[gen] (x:(pos=1) AND (near:(pos=2) PHRASE 2 0:(pos=3)) AND y:(pos=4))
+
+x near/2z y
+[lex] "x" "near/2z" "y"
+[parse] (AND (AND "x" "near/2z") "y")
+[gen] (x:(pos=1) AND (near:(pos=2) PHRASE 2 2z:(pos=3)) AND y:(pos=4))
+
+# The first query below is Xapian-compatible; while the secnd one
+# isn't. In both cases, Xapian initially sees "near" as a NEAR
+# operator, but in the first case the trailing y is a syntax error,
+# which cases Xapian to reparse with no flags.
+x near/z y
+[lex] "x" "near/z" "y"
+[parse] (AND (AND "x" "near/z") "y")
+[gen] (x:(pos=1) AND (near:(pos=2) PHRASE 2 z:(pos=3)) AND y:(pos=4))
+
+x near/z
+[lex] "x" "near/z"
+[parse] (AND "x" "near/z")
+[gen] (x:(pos=1) AND (near:(pos=2) PHRASE 2 z:(pos=3)))
+[xapian] (x:(pos=1) NEAR 11 z:(pos=2))
+
+x adj y adj z
+[lex] "x" ADJ "y" ADJ "z"
+[parse] (ADJ "x" (ADJ "y" (ADJ "z")))
+[gen] (x:(pos=1) PHRASE 12 y:(pos=2) PHRASE 12 z:(pos=3))
+
+# Syntax errors
+# These are all Xapian-incompatible because they're syntax errors.
+(x) NEAR y
+[lex] BRA "x" KET NEAR "y"
+[parse] (AND (AND "x" "NEAR") "y")
+[gen] (x:(pos=1) AND near:(pos=2) AND y:(pos=3))
+
+x NEAR (y)
+[lex] "x" NEAR BRA "y" KET
+[parse] (AND (AND "x" "NEAR") "y")
+[gen] (x:(pos=1) AND near:(pos=2) AND y:(pos=3))
+
+x NEAR y NEAR (z)
+[lex] "x" NEAR "y" NEAR BRA "z" KET
+[parse] (AND (AND (NEAR "x" (NEAR "y")) "NEAR") "z")
+[gen] ((x:(pos=1) NEAR 11 y:(pos=2)) AND near:(pos=3) AND z:(pos=4))
+[xapian] (x:(pos=1) AND near:(pos=2) AND y:(pos=3) AND near:(pos=4) AND z:(pos=5))
+
+x NEAR y ADJ z
+[lex] "x" NEAR "y" ADJ "z"
+[parse] (AND (AND (NEAR "x" (NEAR "y")) "ADJ") "z")
+[gen] ((x:(pos=1) NEAR 11 y:(pos=2)) AND adj:(pos=3) AND z:(pos=4))
+[xapian] (x:(pos=1) AND near:(pos=2) AND y:(pos=3) AND adj:(pos=4) AND z:(pos=5))
+
+NEAR x
+[lex] NEAR "x"
+[parse] (AND "NEAR" "x")
+[gen] (near:(pos=1) AND x:(pos=2))
diff --git a/test/qparser.expected-output/operators b/test/qparser.expected-output/operators
index 788f007..3d69f9b 100644
--- a/test/qparser.expected-output/operators
+++ b/test/qparser.expected-output/operators
@@ -143,3 +143,15 @@ x OR @
[parse] (OR "x" "@")
[gen] x:(pos=1)
[xapian] error Syntax: <expression> OR <expression>
+
+@ NEAR x
+[lex] "@" NEAR "x"
+[parse] (NEAR "@" (NEAR "x"))
+[gen] x:(pos=1)
+[xapian] (near:(pos=1) AND x:(pos=2))
+
+x NEAR @
+[lex] "x" NEAR "@"
+[parse] (NEAR "x" (NEAR "@"))
+[gen] x:(pos=1)
+[xapian] (x:(pos=1) AND near:(pos=2))
diff --git a/test/qparser.expected-output/probs b/test/qparser.expected-output/probs
index 3c166f7..8f50cdc 100644
--- a/test/qparser.expected-output/probs
+++ b/test/qparser.expected-output/probs
@@ -10,6 +10,12 @@
[gen] ((x:(pos=1) OR y:(pos=2)) AND z:(pos=3))
[xapian] (x:(pos=1) AND or:(pos=2) AND y:(pos=3) AND and:(pos=4) AND z:(pos=5))
+# Near binds tighter than hate
+x -y NEAR z
+[lex] "x" HATE "y" NEAR "z"
+[parse] (AND "x" (NOT (NEAR "y" (NEAR "z"))))
+[gen] (x:(pos=1) AND_NOT (y:(pos=2) NEAR 11 z:(pos=3)))
+
# Empty subexpression after prefix
# Incompatible; Xapian treats as a syntax error.
prob:() AND x
--
1.7.2.3
More information about the notmuch
mailing list