remove pesky static parse method that stymies flexibility

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@156600 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2005-03-09 03:21:22 +00:00
parent 835871eedc
commit 4a4221e0a9
3 changed files with 16 additions and 39 deletions

View File

@ -85,18 +85,6 @@ public class PrecedenceQueryParser implements PrecedenceQueryParserConstants {
static final Operator AND = new Operator("AND"); static final Operator AND = new Operator("AND");
} }
/** Parses a query string, returning a {@link org.apache.lucene.search.Query}.
* @param expression the query expression to be parsed.
* @param field the default field for query terms.
* @param analyzer used to find terms in the query text.
* @throws ParseException if the parsing fails
*/
static public Query parse(String expression, String field, Analyzer analyzer)
throws ParseException {
PrecedenceQueryParser parser = new PrecedenceQueryParser(field, analyzer);
return parser.parse(expression);
}
/** Constructs a query parser. /** Constructs a query parser.
* @param f the default field for query terms. * @param f the default field for query terms.
* @param a used to find terms in the query text. * @param a used to find terms in the query text.

View File

@ -108,18 +108,6 @@ public class PrecedenceQueryParser {
static final Operator AND = new Operator("AND"); static final Operator AND = new Operator("AND");
} }
/** Parses a query string, returning a {@link org.apache.lucene.search.Query}.
* @param expression the query expression to be parsed.
* @param field the default field for query terms.
* @param analyzer used to find terms in the query text.
* @throws ParseException if the parsing fails
*/
static public Query parse(String expression, String field, Analyzer analyzer)
throws ParseException {
PrecedenceQueryParser parser = new PrecedenceQueryParser(field, analyzer);
return parser.parse(expression);
}
/** Constructs a query parser. /** Constructs a query parser.
* @param f the default field for query terms. * @param f the default field for query terms.
* @param a used to find terms in the query text. * @param a used to find terms in the query text.

View File

@ -488,7 +488,7 @@ public class TestPrecedenceQueryParser extends TestCase {
q = qp.parse("\"on\"^1.0"); q = qp.parse("\"on\"^1.0");
assertNotNull(q); assertNotNull(q);
q = PrecedenceQueryParser.parse("the^3", "field", new StandardAnalyzer()); q = getParser(new StandardAnalyzer()).parse("the^3");
assertNotNull(q); assertNotNull(q);
} }
@ -521,7 +521,7 @@ public class TestPrecedenceQueryParser extends TestCase {
public void testBooleanQuery() throws Exception { public void testBooleanQuery() throws Exception {
BooleanQuery.setMaxClauseCount(2); BooleanQuery.setMaxClauseCount(2);
try { try {
PrecedenceQueryParser.parse("one two three", "field", new WhitespaceAnalyzer()); getParser(new WhitespaceAnalyzer()).parse("one two three");
fail("ParseException expected due to too many boolean clauses"); fail("ParseException expected due to too many boolean clauses");
} catch (ParseException expected) { } catch (ParseException expected) {
// too many boolean clauses, so ParseException is expected // too many boolean clauses, so ParseException is expected
@ -533,28 +533,29 @@ public class TestPrecedenceQueryParser extends TestCase {
* precedence issue has been corrected. * precedence issue has been corrected.
*/ */
public void testPrecedence() throws Exception { public void testPrecedence() throws Exception {
Query query1 = PrecedenceQueryParser.parse("A AND B OR C AND D", "field", new WhitespaceAnalyzer()); PrecedenceQueryParser parser = getParser(new WhitespaceAnalyzer());
Query query2 = PrecedenceQueryParser.parse("(A AND B) OR (C AND D)", "field", new WhitespaceAnalyzer()); Query query1 = parser.parse("A AND B OR C AND D");
Query query2 = parser.parse("(A AND B) OR (C AND D)");
assertEquals(query1, query2); assertEquals(query1, query2);
query1 = PrecedenceQueryParser.parse("A OR B C", "field", new WhitespaceAnalyzer()); query1 = parser.parse("A OR B C");
query2 = PrecedenceQueryParser.parse("A B C", "field", new WhitespaceAnalyzer()); query2 = parser.parse("A B C");
assertEquals(query1, query2); assertEquals(query1, query2);
query1 = PrecedenceQueryParser.parse("A AND B C", "field", new WhitespaceAnalyzer()); query1 = parser.parse("A AND B C");
query2 = PrecedenceQueryParser.parse("(+A +B) C", "field", new WhitespaceAnalyzer()); query2 = parser.parse("(+A +B) C");
assertEquals(query1, query2); assertEquals(query1, query2);
query1 = PrecedenceQueryParser.parse("A AND NOT B", "field", new WhitespaceAnalyzer()); query1 = parser.parse("A AND NOT B");
query2 = PrecedenceQueryParser.parse("+A -B", "field", new WhitespaceAnalyzer()); query2 = parser.parse("+A -B");
assertEquals(query1, query2); assertEquals(query1, query2);
query1 = PrecedenceQueryParser.parse("A OR NOT B", "field", new WhitespaceAnalyzer()); query1 = parser.parse("A OR NOT B");
query2 = PrecedenceQueryParser.parse("A -B", "field", new WhitespaceAnalyzer()); query2 = parser.parse("A -B");
assertEquals(query1, query2); assertEquals(query1, query2);
query1 = PrecedenceQueryParser.parse("A OR NOT B AND C", "field", new WhitespaceAnalyzer()); query1 = parser.parse("A OR NOT B AND C");
query2 = PrecedenceQueryParser.parse("A (-B +C)", "field", new WhitespaceAnalyzer()); query2 = parser.parse("A (-B +C)");
assertEquals(query1, query2); assertEquals(query1, query2);
} }