From 126f4b18d317fc538e05b7ae3cd43536bdc2daf0 Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Tue, 24 Mar 2009 12:28:13 +0000 Subject: [PATCH] LUCENE-1563:Add example test case for surround query language git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@757762 13f79535-47bb-0310-9956-ffa450edef68 --- contrib/surround/README.txt | 9 ++-- .../surround/query/Test03Distance.java | 52 +++++++++++++------ 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/contrib/surround/README.txt b/contrib/surround/README.txt index 8341aa9ed3a..056f08044ba 100644 --- a/contrib/surround/README.txt +++ b/contrib/surround/README.txt @@ -39,7 +39,7 @@ and(aa,bb,cc) aa and bb and cc 99n(aa,bb,cc) unordered span query with slop 98 20n(aa*,bb*) -3w(a?a or bb?, cc+) +3w(a?a or bb?, cc*) title: text: aa title : text : aa or bb @@ -64,12 +64,11 @@ not compared to Lucene's MultipleFieldQuery. * suffix truncation is implemented very similar to Lucene's PrefixQuery. Wildcards (? and internal *) are implemented with regular expressions -allow further variations. A reimplementation using +to allow further variations. A reimplementation using WildCardTermEnum (correct name?) should be no problem. Warnings about missing terms are sent to System.out, this might -be replaced by another stream. +be replaced by another stream, and tested for in the tests. -BooleanQueryTest.TestCollector uses a results checking method that should +BooleanQueryTst.TestCollector uses a results checking method that should be replaced by the checking method from Lucene's TestBasics.java. - diff --git a/contrib/surround/src/test/org/apache/lucene/queryParser/surround/query/Test03Distance.java b/contrib/surround/src/test/org/apache/lucene/queryParser/surround/query/Test03Distance.java index 0ca41567084..8802d32a2c0 100644 --- a/contrib/surround/src/test/org/apache/lucene/queryParser/surround/query/Test03Distance.java +++ b/contrib/surround/src/test/org/apache/lucene/queryParser/surround/query/Test03Distance.java @@ -59,26 +59,15 @@ public class Test03Distance extends TestCase { SingleFieldTestDb db1 = new SingleFieldTestDb(docs1, fieldName); - String[] docs2 = { - "w1 w2 w3 w4 w5", - "w1 w3 w2 w3", - "" - }; - - SingleFieldTestDb db2 = new SingleFieldTestDb(docs2, fieldName); - - public void distanceTest1(String query, int[] expdnrs) throws Exception { - BooleanQueryTst bqt = new BooleanQueryTst( query, expdnrs, db1, fieldName, this, + private void distanceTst(String query, int[] expdnrs, SingleFieldTestDb db) throws Exception { + BooleanQueryTst bqt = new BooleanQueryTst( query, expdnrs, db, fieldName, this, new BasicQueryFactory(maxBasicQueries)); bqt.setVerbose(verbose); bqt.doTest(); } - public void distanceTest2(String query, int[] expdnrs) throws Exception { - BooleanQueryTst bqt = new BooleanQueryTst( query, expdnrs, db2, fieldName, this, - new BasicQueryFactory(maxBasicQueries)); - bqt.setVerbose(verbose); - bqt.doTest(); + public void distanceTest1(String query, int[] expdnrs) throws Exception { + distanceTst(query, expdnrs, db1); } public void test0W01() throws Exception { @@ -182,6 +171,18 @@ public class Test03Distance extends TestCase { public void test1Ntrunc09() throws Exception { int[] expdnrs = {3}; distanceTest1( "(orda2 OR orda3) 2N (word2 OR worda3)", expdnrs); } + + String[] docs2 = { + "w1 w2 w3 w4 w5", + "w1 w3 w2 w3", + "" + }; + + SingleFieldTestDb db2 = new SingleFieldTestDb(docs2, fieldName); + + public void distanceTest2(String query, int[] expdnrs) throws Exception { + distanceTst(query, expdnrs, db2); + } public void test2Wprefix01() throws Exception { int[] expdnrs = {0}; distanceTest2( "W (w1, w2, w3)", expdnrs); @@ -217,4 +218,25 @@ public class Test03Distance extends TestCase { public void test2Nnested02() throws Exception { int[] expdnrs = {0,1}; distanceTest2( "w1 2N w2 2N w3", expdnrs); } + + String[] docs3 = { + "low pressure temperature inversion and rain", + "when the temperature has a negative height above a depression no precipitation gradient is expected", + "when the temperature has a negative height gradient above a depression no precipitation is expected", + "" + }; + + SingleFieldTestDb db3 = new SingleFieldTestDb(docs3, fieldName); + + public void distanceTest3(String query, int[] expdnrs) throws Exception { + distanceTst(query, expdnrs, db3); + } + + public void test3Example01() throws Exception { + int[] expdnrs = {0,2}; // query does not match doc 1 because "gradient" is in wrong place there. + distanceTest3("50n((low w pressure*) or depression*," + + "5n(temperat*, (invers* or (negativ* 3n gradient*)))," + + "rain* or precipitat*)", + expdnrs); + } }