From 4a4221e0a944cf0dbdc894222fe435b87383fd05 Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Wed, 9 Mar 2005 03:21:22 +0000 Subject: [PATCH] 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 --- .../precedence/PrecedenceQueryParser.java | 12 ------- .../precedence/PrecedenceQueryParser.jj | 12 ------- .../precedence/TestPrecedenceQueryParser.java | 31 ++++++++++--------- 3 files changed, 16 insertions(+), 39 deletions(-) diff --git a/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java b/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java index bf79d765111..ff8950c1255 100644 --- a/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java +++ b/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java @@ -85,18 +85,6 @@ public class PrecedenceQueryParser implements PrecedenceQueryParserConstants { 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. * @param f the default field for query terms. * @param a used to find terms in the query text. diff --git a/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj b/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj index 67b6c1d9ec6..7d84bf16739 100644 --- a/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj +++ b/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj @@ -108,18 +108,6 @@ public class PrecedenceQueryParser { 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. * @param f the default field for query terms. * @param a used to find terms in the query text. diff --git a/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java b/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java index 0e4df700f1c..e0181c32a17 100644 --- a/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java +++ b/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java @@ -223,7 +223,7 @@ public class TestPrecedenceQueryParser extends TestCase { assertQueryEquals("a OR !b", null, "a (-b)"); assertQueryEquals("a OR ! b", null, "a (-b)"); - assertQueryEquals("a OR -b", null, "a (-b)"); + assertQueryEquals("a OR -b", null, "a (-b)"); } public void testPunct() throws Exception { @@ -488,7 +488,7 @@ public class TestPrecedenceQueryParser extends TestCase { q = qp.parse("\"on\"^1.0"); assertNotNull(q); - q = PrecedenceQueryParser.parse("the^3", "field", new StandardAnalyzer()); + q = getParser(new StandardAnalyzer()).parse("the^3"); assertNotNull(q); } @@ -521,7 +521,7 @@ public class TestPrecedenceQueryParser extends TestCase { public void testBooleanQuery() throws Exception { BooleanQuery.setMaxClauseCount(2); 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"); } catch (ParseException expected) { // too many boolean clauses, so ParseException is expected @@ -533,28 +533,29 @@ public class TestPrecedenceQueryParser extends TestCase { * precedence issue has been corrected. */ public void testPrecedence() throws Exception { - 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()); + PrecedenceQueryParser parser = getParser(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); - query1 = PrecedenceQueryParser.parse("A OR B C", "field", new WhitespaceAnalyzer()); - query2 = PrecedenceQueryParser.parse("A B C", "field", new WhitespaceAnalyzer()); + query1 = parser.parse("A OR B C"); + query2 = parser.parse("A B C"); assertEquals(query1, query2); - query1 = PrecedenceQueryParser.parse("A AND B C", "field", new WhitespaceAnalyzer()); - query2 = PrecedenceQueryParser.parse("(+A +B) C", "field", new WhitespaceAnalyzer()); + query1 = parser.parse("A AND B C"); + query2 = parser.parse("(+A +B) C"); assertEquals(query1, query2); - query1 = PrecedenceQueryParser.parse("A AND NOT B", "field", new WhitespaceAnalyzer()); - query2 = PrecedenceQueryParser.parse("+A -B", "field", new WhitespaceAnalyzer()); + query1 = parser.parse("A AND NOT B"); + query2 = parser.parse("+A -B"); assertEquals(query1, query2); - query1 = PrecedenceQueryParser.parse("A OR NOT B", "field", new WhitespaceAnalyzer()); - query2 = PrecedenceQueryParser.parse("A -B", "field", new WhitespaceAnalyzer()); + query1 = parser.parse("A OR NOT B"); + query2 = parser.parse("A -B"); assertEquals(query1, query2); - query1 = PrecedenceQueryParser.parse("A OR NOT B AND C", "field", new WhitespaceAnalyzer()); - query2 = PrecedenceQueryParser.parse("A (-B +C)", "field", new WhitespaceAnalyzer()); + query1 = parser.parse("A OR NOT B AND C"); + query2 = parser.parse("A (-B +C)"); assertEquals(query1, query2); }