mirror of https://github.com/apache/lucene.git
new QueryParser tests
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150145 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2fd0c0205b
commit
fcc15f9a46
|
@ -79,8 +79,6 @@ import java.util.Calendar;
|
|||
|
||||
/**
|
||||
* Tests QueryParser.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TestQueryParser extends TestCase {
|
||||
|
||||
|
@ -138,6 +136,12 @@ public class TestQueryParser extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private int originalMaxClauses;
|
||||
|
||||
public void setUp() {
|
||||
originalMaxClauses = BooleanQuery.getMaxClauseCount();
|
||||
}
|
||||
|
||||
public QueryParser getParser(Analyzer a) throws Exception {
|
||||
if (a == null)
|
||||
a = new SimpleAnalyzer();
|
||||
|
@ -356,6 +360,25 @@ public class TestQueryParser extends TestCase {
|
|||
assertQueryEquals("\\\\", a, "\\\\");
|
||||
assertQueryEquals("\\+blah", a, "\\+blah");
|
||||
assertQueryEquals("\\(blah", a, "\\(blah");
|
||||
|
||||
assertQueryEquals("\\-blah", a, "\\-blah");
|
||||
assertQueryEquals("\\!blah", a, "\\!blah");
|
||||
assertQueryEquals("\\{blah", a, "\\{blah");
|
||||
assertQueryEquals("\\}blah", a, "\\}blah");
|
||||
assertQueryEquals("\\:blah", a, "\\:blah");
|
||||
assertQueryEquals("\\^blah", a, "\\^blah");
|
||||
assertQueryEquals("\\[blah", a, "\\[blah");
|
||||
assertQueryEquals("\\]blah", a, "\\]blah");
|
||||
assertQueryEquals("\\\"blah", a, "\\\"blah");
|
||||
assertQueryEquals("\\(blah", a, "\\(blah");
|
||||
assertQueryEquals("\\)blah", a, "\\)blah");
|
||||
assertQueryEquals("\\~blah", a, "\\~blah");
|
||||
assertQueryEquals("\\*blah", a, "\\*blah");
|
||||
assertQueryEquals("\\?blah", a, "\\?blah");
|
||||
assertQueryEquals("foo \\&& bar", a, "foo \\&& bar");
|
||||
assertQueryEquals("foo \\|| bar", a, "foo \\|| bar");
|
||||
assertQueryEquals("foo \\AND bar", a, "foo \\AND bar");
|
||||
|
||||
}
|
||||
|
||||
public void testSimpleDAO()
|
||||
|
@ -381,6 +404,17 @@ public class TestQueryParser extends TestCase {
|
|||
assertEquals(q.getBoost(), (float) 2.0, (float) 0.5);
|
||||
q = qp.parse("\"on\"^1.0");
|
||||
assertNotNull(q);
|
||||
|
||||
q = QueryParser.parse("the^3", "field", new StandardAnalyzer());
|
||||
assertNotNull(q);
|
||||
}
|
||||
|
||||
public void testException() throws Exception {
|
||||
try {
|
||||
assertQueryEquals("\"some phrase", null, "abc");
|
||||
fail("ParseException expected, not thrown");
|
||||
} catch (ParseException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testCustomQueryParserWildcard() {
|
||||
|
@ -401,4 +435,18 @@ public class TestQueryParser extends TestCase {
|
|||
fail("Fuzzy queries should not be allowed");
|
||||
}
|
||||
|
||||
public void testBooleanQuery() throws Exception {
|
||||
BooleanQuery.setMaxClauseCount(2);
|
||||
try {
|
||||
QueryParser.parse("one two three", "field", new WhitespaceAnalyzer());
|
||||
fail("ParseException expected due to too many boolean clauses");
|
||||
} catch (ParseException expected) {
|
||||
// too many boolean clauses, so ParseException is expected
|
||||
}
|
||||
}
|
||||
|
||||
public void tearDown() {
|
||||
BooleanQuery.setMaxClauseCount(originalMaxClauses);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue