Skip to content

Apache Lucene open-source search software

LUCENE-1971: Remove RangeQuery & Co.

Uwe Schindleref1af60efeca
diff --git a/CHANGES.txt b/CHANGES.txt
index ab63e0f55a8..781ccd0929c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -50,6 +50,9 @@ API Changes
* LUCENE-1753: Make not yet final TokenStreams final to enforce
decorator pattern. (Uwe Schindler)
+* LUCENE-1971: Remove deprecated RangeQuery, RangeFilter and
+ ConstantScoreRangeQuery. (Uwe Schindler)
+
Bug fixes
* LUCENE-1951: When the text provided to WildcardQuery has no wildcard
diff --git a/common-build.xml b/common-build.xml
index 902a76b25f1..2998237691b 100644
--- a/common-build.xml
+++ b/common-build.xml
@@ -42,7 +42,7 @@
<property name="Name" value="Lucene"/>
<property name="dev.version" value="3.0-dev"/>
<property name="version" value="${dev.version}"/>
- <property name="compatibility.tag" value="lucene_2_9_back_compat_tests_20091010"/>
+ <property name="compatibility.tag" value="lucene_2_9_back_compat_tests_20091011"/>
<property name="spec.version" value="${version}"/>
<property name="year" value="2000-${current.year}"/>
<property name="final.name" value="lucene-${name}-${version}"/>
diff --git a/contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.java b/contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.java
index 2335e84a0a2..8445ccc7a23 100644
--- a/contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.java
+++ b/contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.java
@@ -32,7 +32,6 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermRangeFilter;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery;
-import org.apache.lucene.search.ConstantScoreRangeQuery;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
@@ -89,11 +88,11 @@ public class CollationTestBase extends TestCase {
// Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
// orders the U+0698 character before the U+0633 character, so the single
- // index Term below should NOT be returned by a ConstantScoreRangeQuery
+ // index Term below should NOT be returned by a TermRangeQuery
// with a Farsi Collator (or an Arabic one for the case when Farsi is not
// supported).
- // Test ConstantScoreRangeQuery
+ // Test TermRangeQuery
aqp.setUseOldRangeQuery(false);
ScoreDoc[] result
= is.search(aqp.parse("[ \u062F TO \u0698 ]"), null, 1000).scoreDocs;
@@ -174,7 +173,7 @@ public class CollationTestBase extends TestCase {
searcher.close();
}
- public void testFarsiConstantScoreRangeQuery
+ public void testFarsiTermRangeQuery
(Analyzer analyzer, String firstBeg, String firstEnd,
String secondBeg, String secondEnd) throws Exception {
@@ -194,15 +193,15 @@ public class CollationTestBase extends TestCase {
// Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
// orders the U+0698 character before the U+0633 character, so the single
- // index Term below should NOT be returned by a ConstantScoreRangeQuery
+ // index Term below should NOT be returned by a TermRangeQuery
// with a Farsi Collator (or an Arabic one for the case when Farsi is
// not supported).
Query csrq
- = new ConstantScoreRangeQuery("content", firstBeg, firstEnd, true, true);
+ = new TermRangeQuery("content", firstBeg, firstEnd, true, true);
ScoreDoc[] result = search.search(csrq, null, 1000).scoreDocs;
assertEquals("The index Term should not be included.", 0, result.length);
- csrq = new ConstantScoreRangeQuery
+ csrq = new TermRangeQuery
("content", secondBeg, secondEnd, true, true);
result = search.search(csrq, null, 1000).scoreDocs;
assertEquals("The index Term should be included.", 1, result.length);
diff --git a/contrib/collation/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java b/contrib/collation/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java
index fbec34b49a2..4f6563c10b7 100644
--- a/contrib/collation/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java
+++ b/contrib/collation/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java
@@ -58,8 +58,8 @@ public class TestCollationKeyAnalyzer extends CollationTestBase {
secondRangeBeginning, secondRangeEnd);
}
- public void testFarsiConstantScoreRangeQuery() throws Exception {
- testFarsiConstantScoreRangeQuery
+ public void testFarsiTermRangeQuery() throws Exception {
+ testFarsiTermRangeQuery
(analyzer, firstRangeBeginning, firstRangeEnd,
secondRangeBeginning, secondRangeEnd);
}
diff --git a/contrib/collation/src/test/org/apache/lucene/collation/TestCollationKeyFilter.java b/contrib/collation/src/test/org/apache/lucene/collation/TestCollationKeyFilter.java
index 3e9eb56dafb..a462c4630f0 100644
--- a/contrib/collation/src/test/org/apache/lucene/collation/TestCollationKeyFilter.java
+++ b/contrib/collation/src/test/org/apache/lucene/collation/TestCollationKeyFilter.java
@@ -76,8 +76,8 @@ public class TestCollationKeyFilter extends CollationTestBase {
secondRangeBeginning, secondRangeEnd);
}
- public void testFarsiConstantScoreRangeQuery() throws Exception {
- testFarsiConstantScoreRangeQuery
+ public void testFarsiTermRangeQuery() throws Exception {
+ testFarsiTermRangeQuery
(analyzer, firstRangeBeginning, firstRangeEnd,
secondRangeBeginning, secondRangeEnd);
}
diff --git a/contrib/collation/src/test/org/apache/lucene/collation/TestICUCollationKeyAnalyzer.java b/contrib/collation/src/test/org/apache/lucene/collation/TestICUCollationKeyAnalyzer.java
index 5ad4991d39f..19a8359ebcc 100644
--- a/contrib/collation/src/test/org/apache/lucene/collation/TestICUCollationKeyAnalyzer.java
+++ b/contrib/collation/src/test/org/apache/lucene/collation/TestICUCollationKeyAnalyzer.java
@@ -53,8 +53,8 @@ public class TestICUCollationKeyAnalyzer extends CollationTestBase {
secondRangeBeginning, secondRangeEnd);
}
- public void testFarsiConstantScoreRangeQuery() throws Exception {
- testFarsiConstantScoreRangeQuery
+ public void testFarsiTermRangeQuery() throws Exception {
+ testFarsiTermRangeQuery
(analyzer, firstRangeBeginning, firstRangeEnd,
secondRangeBeginning, secondRangeEnd);
}
diff --git a/contrib/collation/src/test/org/apache/lucene/collation/TestICUCollationKeyFilter.java b/contrib/collation/src/test/org/apache/lucene/collation/TestICUCollationKeyFilter.java
index fc5c71e1fc3..f8d0fa5484a 100644
--- a/contrib/collation/src/test/org/apache/lucene/collation/TestICUCollationKeyFilter.java
+++ b/contrib/collation/src/test/org/apache/lucene/collation/TestICUCollationKeyFilter.java
@@ -71,8 +71,8 @@ public class TestICUCollationKeyFilter extends CollationTestBase {
secondRangeBeginning, secondRangeEnd);
}
- public void testFarsiConstantScoreRangeQuery() throws Exception {
- testFarsiConstantScoreRangeQuery
+ public void testFarsiTermRangeQuery() throws Exception {
+ testFarsiTermRangeQuery
(analyzer, firstRangeBeginning, firstRangeEnd,
secondRangeBeginning, secondRangeEnd);
}
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.java
index cbb337791ca..499e60825c0 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
@@ -55,7 +55,6 @@ import org.apache.lucene.index.IndexWriter.MaxFieldLength;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.ConstantScoreRangeQuery;
import org.apache.lucene.search.FilteredQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MultiPhraseQuery;
@@ -557,42 +556,6 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
helper.start();
}
- public void testGetConstantScoreRangeFragments() throws Exception {
-
- numHighlights = 0;
-
- query = new ConstantScoreRangeQuery(FIELD_NAME, "kannedy", "kznnedy", true, true);
-
- searcher = new IndexSearcher(ramDir, true);
- // can't rewrite ConstantScoreRangeQuery if you want to highlight it -
- // it rewrites to ConstantScoreQuery which cannot be highlighted
- // query = unReWrittenQuery.rewrite(reader);
- System.out.println("Searching for: " + query.toString(FIELD_NAME));
- hits = searcher.search(query, null, 1000);
-
- for (int i = 0; i < hits.totalHits; i++) {
- String text = searcher.doc(hits.scoreDocs[i].doc).get(HighlighterTest.FIELD_NAME);
- int maxNumFragmentsRequired = 2;
- String fragmentSeparator = "...";
- QueryScorer scorer = null;
- TokenStream tokenStream = null;
-
- tokenStream = analyzer.tokenStream(HighlighterTest.FIELD_NAME, new StringReader(text));
-
- scorer = new QueryScorer(query, HighlighterTest.FIELD_NAME);
-
- Highlighter highlighter = new Highlighter(this, scorer);
-
- highlighter.setTextFragmenter(new SimpleFragmenter(20));
-
- String result = highlighter.getBestFragments(tokenStream, text, maxNumFragmentsRequired,
- fragmentSeparator);
- System.out.println("\t" + result);
- }
- assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
- numHighlights == 5);
- }
-
public void testConstantScoreMultiTermQuery() throws Exception {
numHighlights = 0;
diff --git a/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java b/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java
index 80928020b03..63dc6c3f77b 100644
--- a/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java
+++ b/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java
@@ -22,7 +22,7 @@ import org.apache.lucene.search.MultiPhraseQuery;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
-import org.apache.lucene.search.RangeQuery;
+import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.util.Parameter;
@@ -428,9 +428,7 @@ public class PrecedenceQueryParser implements PrecedenceQueryParserConstants {
}
catch (Exception e) { }
- return new RangeQuery(new Term(field, part1),
- new Term(field, part2),
- inclusive);
+ return new TermRangeQuery(field, part1, part2, inclusive, inclusive);
}
/**
diff --git a/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj b/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj
index 5c1155265f3..1aa7a241a69 100644
--- a/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj
+++ b/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj
@@ -46,7 +46,7 @@ import org.apache.lucene.search.MultiPhraseQuery;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
-import org.apache.lucene.search.RangeQuery;
+import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.util.Parameter;
@@ -452,9 +452,7 @@ public class PrecedenceQueryParser {
}
catch (Exception e) { }
- return new RangeQuery(new Term(field, part1),
- new Term(field, part2),
- inclusive);
+ return new TermRangeQuery(field, part1, part2, inclusive, inclusive);
}
/**
diff --git a/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java b/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java
index 73d4416bf88..76f5d91e643 100644
--- a/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java
+++ b/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java
@@ -20,7 +20,7 @@ import org.apache.lucene.search.MultiPhraseQuery;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
-import org.apache.lucene.search.RangeQuery;
+import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.util.Parameter;
diff --git a/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java b/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
index 360ffee9a5c..741f079a180 100644
--- a/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
+++ b/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
@@ -32,7 +32,7 @@ import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
-import org.apache.lucene.search.RangeQuery;
+import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.util.LocalizedTestCase;
@@ -359,7 +359,7 @@ public class TestPrecedenceQueryParser extends LocalizedTestCase {
public void testRange() throws Exception {
assertQueryEquals("[ a TO z]", null, "[a TO z]");
- assertTrue(getQuery("[ a TO z]", null) instanceof RangeQuery);
+ assertTrue(getQuery("[ a TO z]", null) instanceof TermRangeQuery);
assertQueryEquals("[ a TO z ]", null, "[a TO z]");
assertQueryEquals("{ a TO z}", null, "{a TO z}");
assertQueryEquals("{ a TO z }", null, "{a TO z}");
diff --git a/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java b/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java
deleted file mode 100644
index 305e9d5f9c7..00000000000
--- a/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.apache.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.text.Collator;
-
-/**
- * A range query that returns a constant score equal to its boost for
- * all documents in the exclusive range of terms.
- *
- * <p>It does not have an upper bound on the number of clauses covered in the range.
- *
- * <p>This query matches the documents looking for terms that fall into the
- * supplied range according to {@link String#compareTo(String)}. It is not intended
- * for numerical ranges, use {@link NumericRangeQuery} instead.
- *
- * <p>This query is hardwired to {@link MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}.
- * If you want to change this, use {@link TermRangeQuery} instead.
- *
- * @deprecated Use {@link TermRangeQuery} for term ranges or
- * {@link NumericRangeQuery} for numeric ranges instead.
- * This class will be removed in Lucene 3.0.
- */
-public class ConstantScoreRangeQuery extends TermRangeQuery
-{
-
- public ConstantScoreRangeQuery(String fieldName, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper)
- {
- super(fieldName, lowerVal, upperVal, includeLower, includeUpper);
- rewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
- }
-
- public ConstantScoreRangeQuery(String fieldName, String lowerVal,
- String upperVal, boolean includeLower,
- boolean includeUpper, Collator collator) {
- super(fieldName, lowerVal, upperVal, includeLower, includeUpper, collator);
- rewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
- }
-
- public String getLowerVal() {
- return getLowerTerm();
- }
-
- public String getUpperVal() {
- return getUpperTerm();
- }
-
- /** Changes of mode are not supported by this class (fixed to constant score rewrite mode) */
- public void setRewriteMethod(RewriteMethod method) {
- throw new UnsupportedOperationException("Use TermRangeQuery instead to change the rewrite method.");
- }
-}
diff --git a/src/java/org/apache/lucene/search/RangeFilter.java b/src/java/org/apache/lucene/search/RangeFilter.java
deleted file mode 100644
index 7b67952dd67..00000000000
--- a/src/java/org/apache/lucene/search/RangeFilter.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.apache.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.text.Collator;
-
-/**
- * A Filter that restricts search results to a range of values in a given
- * field.
- *
- * <p>This filter matches the documents looking for terms that fall into the
- * supplied range according to {@link String#compareTo(String)}. It is not intended
- * for numerical ranges, use {@link NumericRangeFilter} instead.
- *
- * <p>If you construct a large number of range filters with different ranges but on the
- * same field, {@link FieldCacheRangeFilter} may have significantly better performance.
- *
- * @deprecated Use {@link TermRangeFilter} for term ranges or
- * {@link NumericRangeFilter} for numeric ranges instead.
- * This class will be removed in Lucene 3.0.
- */
-public class RangeFilter extends MultiTermQueryWrapperFilter {
-
- /**
- * @param fieldName The field this range applies to
- * @param lowerTerm The lower bound on this range
- * @param upperTerm The upper bound on this range
- * @param includeLower Does this range include the lower bound?
- * @param includeUpper Does this range include the upper bound?
- * @throws IllegalArgumentException if both terms are null or if
- * lowerTerm is null and includeLower is true (similar for upperTerm
- * and includeUpper)
- */
- public RangeFilter(String fieldName, String lowerTerm, String upperTerm,
- boolean includeLower, boolean includeUpper) {
- super(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper));
- }
-
- /**
- * <strong>WARNING:</strong> Using this constructor and supplying a non-null
- * value in the <code>collator</code> parameter will cause every single
- * index Term in the Field referenced by lowerTerm and/or upperTerm to be
- * examined. Depending on the number of index Terms in this Field, the
- * operation could be very slow.
- *
- * @param lowerTerm The lower bound on this range
- * @param upperTerm The upper bound on this range
- * @param includeLower Does this range include the lower bound?
- * @param includeUpper Does this range include the upper bound?
- * @param collator The collator to use when determining range inclusion; set
- * to null to use Unicode code point ordering instead of collation.
- * @throws IllegalArgumentException if both terms are null or if
- * lowerTerm is null and includeLower is true (similar for upperTerm
- * and includeUpper)
- */
- public RangeFilter(String fieldName, String lowerTerm, String upperTerm,
- boolean includeLower, boolean includeUpper,
- Collator collator) {
- super(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper, collator));
- }
-
- /**
- * Constructs a filter for field <code>fieldName</code> matching
- * less than or equal to <code>upperTerm</code>.
- */
- public static RangeFilter Less(String fieldName, String upperTerm) {
- return new RangeFilter(fieldName, null, upperTerm, false, true);
- }
-
- /**
- * Constructs a filter for field <code>fieldName</code> matching
- * greater than or equal to <code>lowerTerm</code>.
- */
- public static RangeFilter More(String fieldName, String lowerTerm) {
- return new RangeFilter(fieldName, lowerTerm, null, true, false);
- }
-}
diff --git a/src/java/org/apache/lucene/search/RangeQuery.java b/src/java/org/apache/lucene/search/RangeQuery.java
deleted file mode 100644
index ee98a54e5ec..00000000000
--- a/src/java/org/apache/lucene/search/RangeQuery.java
+++ /dev/null
@@ -1,154 +0,0 @@
-package org.apache.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.text.Collator;
-import java.io.IOException;
-
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-
-/**
- * A Query that matches documents within an exclusive range of terms.
- *
- * <p>This query matches the documents looking for terms that fall into the
- * supplied range according to {@link Term#compareTo(Term)}. It is not intended
- * for numerical ranges, use {@link NumericRangeQuery} instead.
- *
- * <p>This query uses {@linkplain
- * MultiTermQuery#SCORING_BOOLEAN_QUERY_REWRITE}. If you
- * want to change this, use the new {@link TermRangeQuery}
- * instead.
- *
- * @deprecated Use {@link TermRangeQuery} for term ranges or
- * {@link NumericRangeQuery} for numeric ranges instead.
- * This class will be removed in Lucene 3.0.
- */
-public class RangeQuery extends Query {
- private final TermRangeQuery delegate;
-
- /** Constructs a query selecting all terms greater than
- * <code>lowerTerm</code> but less than <code>upperTerm</code>.
- * There must be at least one term and either term may be null,
- * in which case there is no bound on that side, but if there are
- * two terms, both terms <b>must</b> be for the same field.
- *
- * @param lowerTerm The Term at the lower end of the range
- * @param upperTerm The Term at the upper end of the range
- * @param inclusive If true, both <code>lowerTerm</code> and
- * <code>upperTerm</code> will themselves be included in the range.
- */
- public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive) {
- this(lowerTerm, upperTerm, inclusive, null);
- }
-
- /** Constructs a query selecting all terms greater than
- * <code>lowerTerm</code> but less than <code>upperTerm</code>.
- * There must be at least one term and either term may be null,
- * in which case there is no bound on that side, but if there are
- * two terms, both terms <b>must</b> be for the same field.
- * <p>
- * If <code>collator</code> is not null, it will be used to decide whether
- * index terms are within the given range, rather than using the Unicode code
- * point order in which index terms are stored.
- * <p>
- * <strong>WARNING:</strong> Using this constructor and supplying a non-null
- * value in the <code>collator</code> parameter will cause every single
- * index Term in the Field referenced by lowerTerm and/or upperTerm to be
- * examined. Depending on the number of index Terms in this Field, the
- * operation could be very slow.
- *
- * @param lowerTerm The Term at the lower end of the range
- * @param upperTerm The Term at the upper end of the range
- * @param inclusive If true, both <code>lowerTerm</code> and
- * <code>upperTerm</code> will themselves be included in the range.
- * @param collator The collator to use to collate index Terms, to determine
- * their membership in the range bounded by <code>lowerTerm</code> and
- * <code>upperTerm</code>.
- */
- public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive, Collator collator) {
- if (lowerTerm == null && upperTerm == null)
- throw new IllegalArgumentException("At least one term must be non-null");
- if (lowerTerm != null && upperTerm != null && lowerTerm.field() != upperTerm.field())
- throw new IllegalArgumentException("Both terms must have the same field");
-
- delegate = new TermRangeQuery(
- (lowerTerm == null) ? upperTerm.field() : lowerTerm.field(),
- (lowerTerm == null) ? null : lowerTerm.text(),
- (upperTerm == null) ? null : upperTerm.text(),
- inclusive, inclusive,
- collator
- );
- delegate.setRewriteMethod(TermRangeQuery.SCORING_BOOLEAN_QUERY_REWRITE);
- }
-
- public void setBoost(float b) {
- super.setBoost(b);
- delegate.setBoost(b);
- }
-
- public Query rewrite(IndexReader reader) throws IOException {
- return delegate.rewrite(reader);
- }
-
- /** Returns the field name for this query */
- public String getField() {
- return delegate.getField();
- }
-
- /** Returns the lower term of this range query. */
- public Term getLowerTerm() {
- final String term = delegate.getLowerTerm();
- return (term == null) ? null : new Term(getField(), term);
- }
-
- /** Returns the upper term of this range query. */
- public Term getUpperTerm() {
- final String term = delegate.getUpperTerm();
- return (term == null) ? null : new Term(getField(), term);
- }
-
- /** Returns <code>true</code> if the range query is inclusive */
- public boolean isInclusive() {
- return delegate.includesLower() && delegate.includesUpper();
- }
-
- /** Returns the collator used to determine range inclusion, if any. */
- public Collator getCollator() {
- return delegate.getCollator();
- }
-
- /** Prints a user-readable version of this query. */
- public String toString(String field) {
- return delegate.toString(field);
- }
-
- /** Returns true iff <code>o</code> is equal to this. */
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof RangeQuery)) return false;
-
- final RangeQuery other = (RangeQuery) o;
- return this.delegate.equals(other.delegate);
- }
-
- /** Returns a hash code value for this object.*/
- public int hashCode() {
- return delegate.hashCode();
- }
-}
diff --git a/src/test/org/apache/lucene/search/TestTermRangeQuery.java b/src/test/org/apache/lucene/search/TestTermRangeQuery.java
index 829a277106a..7e128e12d6f 100644
--- a/src/test/org/apache/lucene/search/TestTermRangeQuery.java
+++ b/src/test/org/apache/lucene/search/TestTermRangeQuery.java
@@ -66,23 +66,6 @@ public class TestTermRangeQuery extends LuceneTestCase {
searcher.close();
}
- //TODO: remove in Lucene 3.0
- public void testDeprecatedCstrctors() throws IOException {
- Query query = new RangeQuery(null, new Term("content","C"), false);
- initializeIndex(new String[] {"A", "B", "C", "D"});
- IndexSearcher searcher = new IndexSearcher(dir, true);
- ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
- assertEquals("A,B,C,D, only B in range", 2, hits.length);
- searcher.close();
-
- query = new RangeQuery(new Term("content","C"),null, false);
- initializeIndex(new String[] {"A", "B", "C", "D"});
- searcher = new IndexSearcher(dir, true);
- hits = searcher.search(query, null, 1000).scoreDocs;
- assertEquals("A,B,C,D, only B in range", 1, hits.length);
- searcher.close();
- }
-
public void testInclusive() throws Exception {
Query query = new TermRangeQuery("content", "A", "C", true, true);