mirror of https://github.com/apache/lucene.git
Fix broken QueryParser.jj and generated code. Removed inadvertent debugging <echo> from build.xml.
Added (currently failing) test cases for new PrecedenceQueryParser as a target for enhancement. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@156449 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4f84a76e7b
commit
27614d6a39
|
@ -97,7 +97,6 @@
|
||||||
<srcfiles dir="src" includes="**/*.jj" />
|
<srcfiles dir="src" includes="**/*.jj" />
|
||||||
<mapper type="glob" from="*.jj" to="*.java"/>
|
<mapper type="glob" from="*.jj" to="*.java"/>
|
||||||
</uptodate>
|
</uptodate>
|
||||||
<echo>${javacc.files.uptodate}</echo>
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="javacc-notice" unless="javacc.files.uptodate">
|
<target name="javacc-notice" unless="javacc.files.uptodate">
|
||||||
|
|
|
@ -524,6 +524,7 @@ public class QueryParser implements QueryParserConstants {
|
||||||
protected Query getBooleanQuery(Vector clauses) throws ParseException {
|
protected Query getBooleanQuery(Vector clauses) throws ParseException {
|
||||||
return getBooleanQuery(clauses, false);
|
return getBooleanQuery(clauses, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method for generating query, given a set of clauses.
|
* Factory method for generating query, given a set of clauses.
|
||||||
* By default creates a boolean query composed of clauses passed in.
|
* By default creates a boolean query composed of clauses passed in.
|
||||||
|
|
|
@ -545,8 +545,9 @@ public class QueryParser {
|
||||||
* @exception ParseException throw in overridden method to disallow
|
* @exception ParseException throw in overridden method to disallow
|
||||||
*/
|
*/
|
||||||
protected Query getBooleanQuery(Vector clauses) throws ParseException {
|
protected Query getBooleanQuery(Vector clauses) throws ParseException {
|
||||||
getBooleanQuery(clauses, false);
|
return getBooleanQuery(clauses, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method for generating query, given a set of clauses.
|
* Factory method for generating query, given a set of clauses.
|
||||||
* By default creates a boolean query composed of clauses passed in.
|
* By default creates a boolean query composed of clauses passed in.
|
||||||
|
|
|
@ -170,6 +170,8 @@ public class TestPrecedenceQueryParser extends TestCase {
|
||||||
assertQueryEquals("türm term term", null, "türm term term");
|
assertQueryEquals("türm term term", null, "türm term term");
|
||||||
assertQueryEquals("ümlaut", null, "ümlaut");
|
assertQueryEquals("ümlaut", null, "ümlaut");
|
||||||
|
|
||||||
|
assertQueryEquals("+a", null, "+a");
|
||||||
|
assertQueryEquals("-a", null, "-a");
|
||||||
assertQueryEquals("a AND b", null, "+a +b");
|
assertQueryEquals("a AND b", null, "+a +b");
|
||||||
assertQueryEquals("(a AND b)", null, "+a +b");
|
assertQueryEquals("(a AND b)", null, "+a +b");
|
||||||
assertQueryEquals("c OR (a AND b)", null, "c (+a +b)");
|
assertQueryEquals("c OR (a AND b)", null, "c (+a +b)");
|
||||||
|
@ -325,6 +327,7 @@ public class TestPrecedenceQueryParser extends TestCase {
|
||||||
assertQueryEquals("term AND NOT phrase term", qpAnalyzer,
|
assertQueryEquals("term AND NOT phrase term", qpAnalyzer,
|
||||||
"(+term -\"phrase1 phrase2\") term");
|
"(+term -\"phrase1 phrase2\") term");
|
||||||
assertQueryEquals("stop", qpAnalyzer, "");
|
assertQueryEquals("stop", qpAnalyzer, "");
|
||||||
|
assertQueryEquals("stop OR stop AND stop", qpAnalyzer, "");
|
||||||
assertTrue(getQuery("term term term", qpAnalyzer) instanceof BooleanQuery);
|
assertTrue(getQuery("term term term", qpAnalyzer) instanceof BooleanQuery);
|
||||||
assertTrue(getQuery("term +stop", qpAnalyzer) instanceof TermQuery);
|
assertTrue(getQuery("term +stop", qpAnalyzer) instanceof TermQuery);
|
||||||
}
|
}
|
||||||
|
@ -530,11 +533,9 @@ public class TestPrecedenceQueryParser extends TestCase {
|
||||||
Query query1 = PrecedenceQueryParser.parse("A AND B OR C AND D", "field", new WhitespaceAnalyzer());
|
Query query1 = PrecedenceQueryParser.parse("A AND B OR C AND D", "field", new WhitespaceAnalyzer());
|
||||||
Query query2 = PrecedenceQueryParser.parse("(A AND B) OR (C AND D)", "field", new WhitespaceAnalyzer());
|
Query query2 = PrecedenceQueryParser.parse("(A AND B) OR (C AND D)", "field", new WhitespaceAnalyzer());
|
||||||
assertEquals(query1, query2);
|
assertEquals(query1, query2);
|
||||||
}
|
|
||||||
|
|
||||||
public void testPrecedenceWithNot() throws Exception {
|
query1 = PrecedenceQueryParser.parse("A OR B C", "field", new WhitespaceAnalyzer());
|
||||||
Query query1 = PrecedenceQueryParser.parse("A OR B C", "field", new WhitespaceAnalyzer());
|
query2 = PrecedenceQueryParser.parse("A B C", "field", new WhitespaceAnalyzer());
|
||||||
Query query2 = PrecedenceQueryParser.parse("A B C", "field", new WhitespaceAnalyzer());
|
|
||||||
assertEquals(query1, query2);
|
assertEquals(query1, query2);
|
||||||
|
|
||||||
query1 = PrecedenceQueryParser.parse("A AND B C", "field", new WhitespaceAnalyzer());
|
query1 = PrecedenceQueryParser.parse("A AND B C", "field", new WhitespaceAnalyzer());
|
||||||
|
@ -548,8 +549,11 @@ public class TestPrecedenceQueryParser extends TestCase {
|
||||||
query1 = PrecedenceQueryParser.parse("A OR NOT B", "field", new WhitespaceAnalyzer());
|
query1 = PrecedenceQueryParser.parse("A OR NOT B", "field", new WhitespaceAnalyzer());
|
||||||
query2 = PrecedenceQueryParser.parse("A -B", "field", new WhitespaceAnalyzer());
|
query2 = PrecedenceQueryParser.parse("A -B", "field", new WhitespaceAnalyzer());
|
||||||
assertEquals(query1, query2);
|
assertEquals(query1, query2);
|
||||||
}
|
|
||||||
|
|
||||||
|
query1 = PrecedenceQueryParser.parse("A OR NOT B AND C", "field", new WhitespaceAnalyzer());
|
||||||
|
query2 = PrecedenceQueryParser.parse("A (-B +C)", "field", new WhitespaceAnalyzer());
|
||||||
|
assertEquals(query1, query2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
|
Loading…
Reference in New Issue