Apache Solr open-source search software
Remove deprecations from QueryParser and generify (LUCENE-1257) QueryParser
Uwe Schindler649a0e83a471
diff --git a/common-build.xml b/common-build.xmlindex 191baee70fe..7c9c70d78b5 100644--- a/common-build.xml+++ b/common-build.xml@@ -200,10 +200,10 @@Then, create a build.properties file either in your homedirectory, or within the Lucene directory and set the javacc.homeproperty to the path where JavaCC is installed. For example,- if you installed JavaCC in /usr/local/java/javacc-3.2, then set the+ if you installed JavaCC in /usr/local/java/javacc-4.1, then set thejavacc.home property to:- javacc.home=/usr/local/java/javacc-3.2+ javacc.home=/usr/local/java/javacc-4.1If you get an error like the one below, then you have not installedthings correctly. Please check all your paths and try again.diff --git a/contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.java b/contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.javaindex 8445ccc7a23..a1ceb3376c1 100644--- a/contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.java+++ b/contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.java@@ -93,7 +93,6 @@ public class CollationTestBase extends TestCase {// supported).// Test TermRangeQuery- aqp.setUseOldRangeQuery(false);ScoreDoc[] result= is.search(aqp.parse("[ \u062F TO \u0698 ]"), null, 1000).scoreDocs;assertEquals("The index Term should not be included.", 0, result.length);@@ -101,14 +100,6 @@ public class CollationTestBase extends TestCase {result = is.search(aqp.parse("[ \u0633 TO \u0638 ]"), null, 1000).scoreDocs;assertEquals("The index Term should be included.", 1, result.length);- // Test TermRangeQuery- aqp.setUseOldRangeQuery(true);- result = is.search(aqp.parse("[ \u062F TO \u0698 ]"), null, 1000).scoreDocs;- assertEquals("The index Term should not be included.", 0, result.length);-- result = is.search(aqp.parse("[ \u0633 TO \u0638 ]"), null, 1000).scoreDocs;- assertEquals("The index Term should be included.", 1, result.length);-is.close();}diff --git a/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java b/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.javaindex 499e60825c0..0ba7ec83bfc 100644--- a/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java+++ b/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java@@ -543,7 +543,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte// rather// than RangeFiltersQueryParser parser = new QueryParser(FIELD_NAME, new StandardAnalyzer());- parser.setUseOldRangeQuery(true);+ parser.setMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);query = parser.parse(queryString);doSearching(query);diff --git a/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java b/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.javaindex a73dcfc8d01..9e8017eef98 100644--- a/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java+++ b/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java@@ -36,7 +36,7 @@ import org.apache.lucene.search.Query;public class MultiFieldQueryParser extends QueryParser{protected String[] fields;- protected Map boosts;+ protected Map<String,Float> boosts;/*** Creates a MultiFieldQueryParser.@@ -65,7 +65,7 @@ public class MultiFieldQueryParser extends QueryParser* <p>In other words, all the query's terms must appear, but it doesn't matter in* what fields they appear.</p>*/- public MultiFieldQueryParser(String[] fields, Analyzer analyzer, Map boosts) {+ public MultiFieldQueryParser(String[] fields, Analyzer analyzer, Map<String,Float> boosts) {this(fields,analyzer);this.boosts = boosts;}@@ -97,14 +97,14 @@ public class MultiFieldQueryParser extends QueryParserprotected Query getFieldQuery(String field, String queryText, int slop) throws ParseException {if (field == null) {- List clauses = new ArrayList();+ List<BooleanClause> clauses = new ArrayList<BooleanClause>();for (int i = 0; i < fields.length; i++) {Query q = super.getFieldQuery(fields[i], queryText);if (q != null) {//If the user passes a map of boostsif (boosts != null) {//Get the boost from the map and apply them- Float boost = (Float)boosts.get(fields[i]);+ Float boost = boosts.get(fields[i]);if (boost != null) {q.setBoost(boost.floatValue());}@@ -139,7 +139,7 @@ public class MultiFieldQueryParser extends QueryParserprotected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException{if (field == null) {- List clauses = new ArrayList();+ List<BooleanClause> clauses = new ArrayList<BooleanClause>();for (int i = 0; i < fields.length; i++) {clauses.add(new BooleanClause(getFuzzyQuery(fields[i], termStr, minSimilarity),BooleanClause.Occur.SHOULD));@@ -152,7 +152,7 @@ public class MultiFieldQueryParser extends QueryParserprotected Query getPrefixQuery(String field, String termStr) throws ParseException{if (field == null) {- List clauses = new ArrayList();+ List<BooleanClause> clauses = new ArrayList<BooleanClause>();for (int i = 0; i < fields.length; i++) {clauses.add(new BooleanClause(getPrefixQuery(fields[i], termStr),BooleanClause.Occur.SHOULD));@@ -164,7 +164,7 @@ public class MultiFieldQueryParser extends QueryParserprotected Query getWildcardQuery(String field, String termStr) throws ParseException {if (field == null) {- List clauses = new ArrayList();+ List<BooleanClause> clauses = new ArrayList<BooleanClause>();for (int i = 0; i < fields.length; i++) {clauses.add(new BooleanClause(getWildcardQuery(fields[i], termStr),BooleanClause.Occur.SHOULD));@@ -177,7 +177,7 @@ public class MultiFieldQueryParser extends QueryParserprotected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {if (field == null) {- List clauses = new ArrayList();+ List<BooleanClause> clauses = new ArrayList<BooleanClause>();for (int i = 0; i < fields.length; i++) {clauses.add(new BooleanClause(getRangeQuery(fields[i], part1, part2, inclusive),BooleanClause.Occur.SHOULD));diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.java b/src/java/org/apache/lucene/queryParser/QueryParser.javaindex 4d2cc407f9b..d34a91b7c27 100644--- a/src/java/org/apache/lucene/queryParser/QueryParser.java+++ b/src/java/org/apache/lucene/queryParser/QueryParser.java@@ -137,7 +137,7 @@ public class QueryParser implements QueryParserConstants {// the default date resolutionDateTools.Resolution dateResolution = null;// maps field names to date resolutions- Map fieldToDateResolution = null;+ Map<String,DateTools.Resolution> fieldToDateResolution = null;// The collator to use when determining range inclusion,// for use when constructing RangeQuerys.@@ -335,29 +335,6 @@ public class QueryParser implements QueryParserConstants {return lowercaseExpandedTerms;}- /**- * @deprecated Please use {@link #setMultiTermRewriteMethod} instead.- */- public void setUseOldRangeQuery(boolean useOldRangeQuery) {- if (useOldRangeQuery) {- setMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);- } else {- setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);- }- }--- /**- * @deprecated Please use {@link #getMultiTermRewriteMethod} instead.- */- public boolean getUseOldRangeQuery() {- if (getMultiTermRewriteMethod() == MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE) {- return true;- } else {- return false;- }- }-/*** By default QueryParser uses {@link MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}* when creating a PrefixQuery, WildcardQuery or RangeQuery. This implementation is generally preferable because it@@ -418,7 +395,7 @@ public class QueryParser implements QueryParserConstants {if (fieldToDateResolution == null) {// lazily initialize HashMap- fieldToDateResolution = new HashMap();+ fieldToDateResolution = new HashMap<String,DateTools.Resolution>();}fieldToDateResolution.put(fieldName, dateResolution);@@ -473,20 +450,13 @@ public class QueryParser implements QueryParserConstants {return rangeCollator;}- /**- * @deprecated use {@link #addClause(List, int, int, Query)} instead.- */- protected void addClause(Vector clauses, int conj, int mods, Query q) {- addClause((List) clauses, conj, mods, q);- }-- protected void addClause(List clauses, int conj, int mods, Query q) {+ protected void addClause(List<BooleanClause> clauses, int conj, int mods, Query q) {boolean required, prohibited;// If this term is introduced by AND, make the preceding term required,// unless it's already prohibitedif (clauses.size() > 0 && conj == CONJ_AND) {- BooleanClause c = (BooleanClause) clauses.get(clauses.size()-1);+ BooleanClause c = clauses.get(clauses.size()-1);if (!c.isProhibited())c.setOccur(BooleanClause.Occur.MUST);}@@ -496,7 +466,7 @@ public class QueryParser implements QueryParserConstants {// unless it's prohibited (that means we leave -a OR b but +a OR b-->a OR b)// notice if the input is a OR b, first term is parsed as required; without// this modification a OR b would parsed as +a OR b- BooleanClause c = (BooleanClause) clauses.get(clauses.size()-1);+ BooleanClause c = clauses.get(clauses.size()-1);if (!c.isProhibited())c.setOccur(BooleanClause.Occur.SHOULD);}@@ -635,7 +605,7 @@ public class QueryParser implements QueryParserConstants {// phrase query:MultiPhraseQuery mpq = newMultiPhraseQuery();mpq.setSlop(phraseSlop);- List multiTerms = new ArrayList();+ List<Term> multiTerms = new ArrayList<Term>();int position = -1;for (int i = 0; i < numTokens; i++) {String term = null;@@ -653,9 +623,9 @@ public class QueryParser implements QueryParserConstants {if (positionIncrement > 0 && multiTerms.size() > 0) {if (enablePositionIncrements) {- mpq.add((Term[])multiTerms.toArray(new Term[0]),position);+ mpq.add(multiTerms.toArray(new Term[0]),position);} else {- mpq.add((Term[])multiTerms.toArray(new Term[0]));+ mpq.add(multiTerms.toArray(new Term[0]));}multiTerms.clear();}@@ -663,9 +633,9 @@ public class QueryParser implements QueryParserConstants {multiTerms.add(new Term(field, term));}if (enablePositionIncrements) {- mpq.add((Term[])multiTerms.toArray(new Term[0]),position);+ mpq.add(multiTerms.toArray(new Term[0]),position);} else {- mpq.add((Term[])multiTerms.toArray(new Term[0]));+ mpq.add(multiTerms.toArray(new Term[0]));}return mpq;}@@ -873,24 +843,6 @@ public class QueryParser implements QueryParserConstants {return query;}- /**- * Factory method for generating query, given a set of clauses.- * By default creates a boolean query composed of clauses passed in.- *- * Can be overridden by extending classes, to modify query being- * returned.- *- * @param clauses List that contains {@link BooleanClause} instances- * to join.- *- * @return Resulting {@link Query} object.- * @exception ParseException throw in overridden method to disallow- * @deprecated use {@link #getBooleanQuery(List)} instead- */- protected Query getBooleanQuery(Vector clauses) throws ParseException {- return getBooleanQuery((List) clauses, false);- }-/*** Factory method for generating query, given a set of clauses.* By default creates a boolean query composed of clauses passed in.@@ -904,31 +856,10 @@ public class QueryParser implements QueryParserConstants {* @return Resulting {@link Query} object.* @exception ParseException throw in overridden method to disallow*/- protected Query getBooleanQuery(List clauses) throws ParseException {+ protected Query getBooleanQuery(List<BooleanClause> clauses) throws ParseException {return getBooleanQuery(clauses, false);}- /**- * Factory method for generating query, given a set of clauses.- * By default creates a boolean query composed of clauses passed in.- *- * Can be overridden by extending classes, to modify query being- * returned.- *- * @param clauses List that contains {@link BooleanClause} instances- * to join.- * @param disableCoord true if coord scoring should be disabled.- *- * @return Resulting {@link Query} object.- * @exception ParseException throw in overridden method to disallow- * @deprecated use {@link #getBooleanQuery(List, boolean)} instead- */- protected Query getBooleanQuery(Vector clauses, boolean disableCoord)- throws ParseException- {- return getBooleanQuery((List) clauses, disableCoord);- }-/*** Factory method for generating query, given a set of clauses.* By default creates a boolean query composed of clauses passed in.@@ -943,15 +874,15 @@ public class QueryParser implements QueryParserConstants {* @return Resulting {@link Query} object.* @exception ParseException throw in overridden method to disallow*/- protected Query getBooleanQuery(List clauses, boolean disableCoord)+ protected Query getBooleanQuery(List<BooleanClause> clauses, boolean disableCoord)throws ParseException{if (clauses.size()==0) {return null; // all clause words were filtered away by the analyzer.}BooleanQuery query = newBooleanQuery(disableCoord);- for (int i = 0; i < clauses.size(); i++) {- query.add((BooleanClause)clauses.get(i));+ for(final BooleanClause clause: clauses) {+ query.add(clause);}return query;}@@ -1234,7 +1165,7 @@ public class QueryParser implements QueryParserConstants {}final public Query Query(String field) throws ParseException {- List clauses = new ArrayList();+ List<BooleanClause> clauses = new ArrayList<BooleanClause>();Query q, firstQuery=null;int conj, mods;mods = Modifiers();diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.jj b/src/java/org/apache/lucene/queryParser/QueryParser.jjindex af0b4e59b86..13a0d9dd11b 100644--- a/src/java/org/apache/lucene/queryParser/QueryParser.jj+++ b/src/java/org/apache/lucene/queryParser/QueryParser.jj@@ -161,7 +161,7 @@ public class QueryParser {// the default date resolutionDateTools.Resolution dateResolution = null;// maps field names to date resolutions- Map fieldToDateResolution = null;+ Map<String,DateTools.Resolution> fieldToDateResolution = null;// The collator to use when determining range inclusion,// for use when constructing RangeQuerys.@@ -359,29 +359,6 @@ public class QueryParser {return lowercaseExpandedTerms;}- /**- * @deprecated Please use {@link #setMultiTermRewriteMethod} instead.- */- public void setUseOldRangeQuery(boolean useOldRangeQuery) {- if (useOldRangeQuery) {- setMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);- } else {- setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);- }- }--- /**- * @deprecated Please use {@link #getMultiTermRewriteMethod} instead.- */- public boolean getUseOldRangeQuery() {- if (getMultiTermRewriteMethod() == MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE) {- return true;- } else {- return false;- }- }-/*** By default QueryParser uses {@link MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}* when creating a PrefixQuery, WildcardQuery or RangeQuery. This implementation is generally preferable because it@@ -442,7 +419,7 @@ public class QueryParser {if (fieldToDateResolution == null) {// lazily initialize HashMap- fieldToDateResolution = new HashMap();+ fieldToDateResolution = new HashMap<String,DateTools.Resolution>();}fieldToDateResolution.put(fieldName, dateResolution);@@ -497,20 +474,13 @@ public class QueryParser {return rangeCollator;}- /**- * @deprecated use {@link #addClause(List, int, int, Query)} instead.- */- protected void addClause(Vector clauses, int conj, int mods, Query q) {- addClause((List) clauses, conj, mods, q);- }-- protected void addClause(List clauses, int conj, int mods, Query q) {+ protected void addClause(List<BooleanClause> clauses, int conj, int mods, Query q) {boolean required, prohibited;// If this term is introduced by AND, make the preceding term required,// unless it's already prohibitedif (clauses.size() > 0 && conj == CONJ_AND) {- BooleanClause c = (BooleanClause) clauses.get(clauses.size()-1);+ BooleanClause c = clauses.get(clauses.size()-1);if (!c.isProhibited())c.setOccur(BooleanClause.Occur.MUST);}@@ -520,7 +490,7 @@ public class QueryParser {// unless it's prohibited (that means we leave -a OR b but +a OR b-->a OR b)// notice if the input is a OR b, first term is parsed as required; without// this modification a OR b would parsed as +a OR b- BooleanClause c = (BooleanClause) clauses.get(clauses.size()-1);+ BooleanClause c = clauses.get(clauses.size()-1);if (!c.isProhibited())c.setOccur(BooleanClause.Occur.SHOULD);}@@ -659,7 +629,7 @@ public class QueryParser {// phrase query:MultiPhraseQuery mpq = newMultiPhraseQuery();mpq.setSlop(phraseSlop);- List multiTerms = new ArrayList();+ List<Term> multiTerms = new ArrayList<Term>();int position = -1;for (int i = 0; i < numTokens; i++) {String term = null;@@ -677,9 +647,9 @@ public class QueryParser {if (positionIncrement > 0 && multiTerms.size() > 0) {if (enablePositionIncrements) {- mpq.add((Term[])multiTerms.toArray(new Term[0]),position);+ mpq.add(multiTerms.toArray(new Term[0]),position);} else {- mpq.add((Term[])multiTerms.toArray(new Term[0]));+ mpq.add(multiTerms.toArray(new Term[0]));}multiTerms.clear();}@@ -687,9 +657,9 @@ public class QueryParser {multiTerms.add(new Term(field, term));}if (enablePositionIncrements) {- mpq.add((Term[])multiTerms.toArray(new Term[0]),position);+ mpq.add(multiTerms.toArray(new Term[0]),position);} else {- mpq.add((Term[])multiTerms.toArray(new Term[0]));+ mpq.add(multiTerms.toArray(new Term[0]));}return mpq;}@@ -897,24 +867,6 @@ public class QueryParser {return query;}- /**- * Factory method for generating query, given a set of clauses.- * By default creates a boolean query composed of clauses passed in.- *- * Can be overridden by extending classes, to modify query being- * returned.- *- * @param clauses List that contains {@link BooleanClause} instances- * to join.- *- * @return Resulting {@link Query} object.- * @exception ParseException throw in overridden method to disallow- * @deprecated use {@link #getBooleanQuery(List)} instead- */- protected Query getBooleanQuery(Vector clauses) throws ParseException {- return getBooleanQuery((List) clauses, false);- }-/*** Factory method for generating query, given a set of clauses.* By default creates a boolean query composed of clauses passed in.@@ -928,31 +880,10 @@ public class QueryParser {* @return Resulting {@link Query} object.* @exception ParseException throw in overridden method to disallow*/- protected Query getBooleanQuery(List clauses) throws ParseException {+ protected Query getBooleanQuery(List<BooleanClause> clauses) throws ParseException {return getBooleanQuery(clauses, false);}- /**- * Factory method for generating query, given a set of clauses.- * By default creates a boolean query composed of clauses passed in.- *- * Can be overridden by extending classes, to modify query being- * returned.- *- * @param clauses List that contains {@link BooleanClause} instances- * to join.- * @param disableCoord true if coord scoring should be disabled.- *- * @return Resulting {@link Query} object.- * @exception ParseException throw in overridden method to disallow- * @deprecated use {@link #getBooleanQuery(List, boolean)} instead- */- protected Query getBooleanQuery(Vector clauses, boolean disableCoord)- throws ParseException- {- return getBooleanQuery((List) clauses, disableCoord);- }-/*** Factory method for generating query, given a set of clauses.* By default creates a boolean query composed of clauses passed in.@@ -967,15 +898,15 @@ public class QueryParser {* @return Resulting {@link Query} object.* @exception ParseException throw in overridden method to disallow*/- protected Query getBooleanQuery(List clauses, boolean disableCoord)+ protected Query getBooleanQuery(List<BooleanClause> clauses, boolean disableCoord)throws ParseException{if (clauses.size()==0) {return null; // all clause words were filtered away by the analyzer.}BooleanQuery query = newBooleanQuery(disableCoord);- for (int i = 0; i < clauses.size(); i++) {- query.add((BooleanClause)clauses.get(i));+ for(final BooleanClause clause: clauses) {+ query.add(clause);}return query;}@@ -1286,7 +1217,7 @@ Query TopLevelQuery(String field) :Query Query(String field) :{- List clauses = new ArrayList();+ List<BooleanClause> clauses = new ArrayList<BooleanClause>();Query q, firstQuery=null;int conj, mods;}