diff --git a/BUILD.txt b/BUILD.txt
index 3b471f63fbd..4feaeaa5efd 100644
--- a/BUILD.txt
+++ b/BUILD.txt
@@ -67,7 +67,8 @@ Step 3) Install JavaCC
Building the Lucene distribution from the source does not require the JavaCC
parser generator, but if you wish to regenerate any of the pre-generated
-parser pieces, you will need to install JavaCC.
+parser pieces, you will need to install JavaCC. Version 4.1 is tested to
+work correctly.
http://javacc.dev.java.net
diff --git a/CHANGES.txt b/CHANGES.txt
index 96bba643a01..5ff60ec89b1 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -281,6 +281,12 @@ API Changes
includes more detailed status than previously. (Tim Smith via
Mike McCandless)
+28. LUCENE-1713: Deprecated RangeQuery and RangeFilter and renamed
+ to TermRangeQuery and TermRangeFilter. TermRangeQuery is in
+ constant score rewrite mode by default. The new classes also have
+ new ctors taking field and term ranges as Strings (see also
+ LUCENE-1424). (Uwe Schindler)
+
Bug fixes
1. LUCENE-1415: MultiPhraseQuery has incorrect hashCode() and equals()
@@ -374,7 +380,7 @@ New features
packaged as War file (Mark Harwood)
6. LUCENE-1424: Moved constant score query rewrite capability into
- MultiTermQuery, allowing RangeQuery, PrefixQuery and WildcardQuery
+ MultiTermQuery, allowing TermRangeQuery, PrefixQuery and WildcardQuery
to switch betwen constant-score rewriting or BooleanQuery
expansion rewriting via a new setConstantScoreRewrite method.
Deprecated ConstantScoreRangeQuery (Mark Miller via Mike
diff --git a/common-build.xml b/common-build.xml
index 1d27e3be304..37c0e25d881 100644
--- a/common-build.xml
+++ b/common-build.xml
@@ -42,7 +42,7 @@
Note that this class saves dates with millisecond granularity, - * which is bad for {@link RangeQuery} and {@link PrefixQuery}, as those + * which is bad for {@link TermRangeQuery} and {@link PrefixQuery}, as those * queries are expanded to a BooleanQuery with a potentially large number * of terms when searching. Thus you might want to use * {@link DateTools} instead. diff --git a/src/java/org/apache/lucene/queryParser/CharStream.java b/src/java/org/apache/lucene/queryParser/CharStream.java index 9e546d50a41..4423996dadf 100644 --- a/src/java/org/apache/lucene/queryParser/CharStream.java +++ b/src/java/org/apache/lucene/queryParser/CharStream.java @@ -109,4 +109,4 @@ public interface CharStream { void Done(); } -/* JavaCC - OriginalChecksum=a83909a2403f969f94d18375f9f143e4 (do not edit this line) */ +/* JavaCC - OriginalChecksum=32a89423891f765dde472f7ef0e3ef7b (do not edit this line) */ diff --git a/src/java/org/apache/lucene/queryParser/ParseException.java b/src/java/org/apache/lucene/queryParser/ParseException.java index fdb47847a38..b48a44644d8 100644 --- a/src/java/org/apache/lucene/queryParser/ParseException.java +++ b/src/java/org/apache/lucene/queryParser/ParseException.java @@ -195,4 +195,4 @@ public class ParseException extends Exception { } } -/* JavaCC - OriginalChecksum=c63b396885c4ff44d7aa48d3feae60cd (do not edit this line) */ +/* JavaCC - OriginalChecksum=c7631a240f7446940695eac31d9483ca (do not edit this line) */ diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.java b/src/java/org/apache/lucene/queryParser/QueryParser.java index b6c9632c81b..c04048f56ae 100644 --- a/src/java/org/apache/lucene/queryParser/QueryParser.java +++ b/src/java/org/apache/lucene/queryParser/QueryParser.java @@ -31,7 +31,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; @@ -173,7 +173,6 @@ public class QueryParser implements QueryParserConstants { return res!=null ? res : newBooleanQuery(false); } catch (ParseException tme) { - // rethrow to include the original query: // rethrow to include the original query: ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage()); e.initCause(tme); @@ -877,22 +876,15 @@ public class QueryParser implements QueryParserConstants { } /** - * Builds a new RangeQuery instance + * Builds a new TermRangeQuery instance * @param field Field * @param part1 min * @param part2 max * @param inclusive true if range is inclusive - * @return new RangeQuery instance + * @return new TermRangeQuery instance */ protected Query newRangeQuery(String field, String part1, String part2, boolean inclusive) { - RangeQuery query; - - if (constantScoreRewrite) { - // TODO: remove in Lucene 3.0 - query = new ConstantScoreRangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator); - } else { - query = new RangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator); - } + final TermRangeQuery query = new TermRangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator); query.setConstantScoreRewrite(constantScoreRewrite); return query; } diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.jj b/src/java/org/apache/lucene/queryParser/QueryParser.jj index fe655a6ce37..74b587258d3 100644 --- a/src/java/org/apache/lucene/queryParser/QueryParser.jj +++ b/src/java/org/apache/lucene/queryParser/QueryParser.jj @@ -55,7 +55,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; @@ -198,13 +198,19 @@ public class QueryParser { } catch (ParseException tme) { // rethrow to include the original query: - throw new ParseException("Cannot parse '" +query+ "': " + tme.getMessage()); + ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage()); + e.initCause(tme); + throw e; } catch (TokenMgrError tme) { - throw new ParseException("Cannot parse '" +query+ "': " + tme.getMessage()); + ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage()); + e.initCause(tme); + throw e; } catch (BooleanQuery.TooManyClauses tmc) { - throw new ParseException("Cannot parse '" +query+ "': too many boolean clauses"); + ParseException e = new ParseException("Cannot parse '" +query+ "': too many boolean clauses"); + e.initCause(tmc); + throw e; } } @@ -894,22 +900,15 @@ public class QueryParser { } /** - * Builds a new RangeQuery instance + * Builds a new TermRangeQuery instance * @param field Field * @param part1 min * @param part2 max * @param inclusive true if range is inclusive - * @return new RangeQuery instance + * @return new TermRangeQuery instance */ protected Query newRangeQuery(String field, String part1, String part2, boolean inclusive) { - RangeQuery query; - - if (constantScoreRewrite) { - // TODO: remove in Lucene 3.0 - query = new ConstantScoreRangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator); - } else { - query = new RangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator); - } + final TermRangeQuery query = new TermRangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator); query.setConstantScoreRewrite(constantScoreRewrite); return query; } diff --git a/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java b/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java index 5b20f4435e7..f3992bce6f3 100644 --- a/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java +++ b/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java @@ -29,7 +29,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/src/java/org/apache/lucene/queryParser/Token.java b/src/java/org/apache/lucene/queryParser/Token.java index 97677981cd7..2c665d6ab22 100644 --- a/src/java/org/apache/lucene/queryParser/Token.java +++ b/src/java/org/apache/lucene/queryParser/Token.java @@ -121,4 +121,4 @@ public class Token { } } -/* JavaCC - OriginalChecksum=37b1923f964a5a434f5ea3d6952ff200 (do not edit this line) */ +/* JavaCC - OriginalChecksum=c147cc166a7cf8812c7c39bc8c5eb868 (do not edit this line) */ diff --git a/src/java/org/apache/lucene/queryParser/TokenMgrError.java b/src/java/org/apache/lucene/queryParser/TokenMgrError.java index 2208bc238ae..3dff0aeb512 100644 --- a/src/java/org/apache/lucene/queryParser/TokenMgrError.java +++ b/src/java/org/apache/lucene/queryParser/TokenMgrError.java @@ -137,4 +137,4 @@ public class TokenMgrError extends Error this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); } } -/* JavaCC - OriginalChecksum=55cddb2336a66b376c0bb59d916b326d (do not edit this line) */ +/* JavaCC - OriginalChecksum=186d5bcc64733844c7daab5ad5a6e349 (do not edit this line) */ diff --git a/src/java/org/apache/lucene/search/BooleanQuery.java b/src/java/org/apache/lucene/search/BooleanQuery.java index 6f6673cb760..4484602eaf2 100644 --- a/src/java/org/apache/lucene/search/BooleanQuery.java +++ b/src/java/org/apache/lucene/search/BooleanQuery.java @@ -34,7 +34,7 @@ public class BooleanQuery extends Query { /** Thrown when an attempt is made to add more than {@link * #getMaxClauseCount()} clauses. This typically happens if - * a PrefixQuery, FuzzyQuery, WildcardQuery, or RangeQuery + * a PrefixQuery, FuzzyQuery, WildcardQuery, or TermRangeQuery * is expanded to many terms during search. */ public static class TooManyClauses extends RuntimeException { @@ -58,8 +58,8 @@ public class BooleanQuery extends Query { * so this parameter indirectly controls the maximum buffer requirements for * query search. *
When this parameter becomes a bottleneck for a Query one can use a - * Filter. For example instead of a {@link RangeQuery} one can use a - * {@link RangeFilter}. + * Filter. For example instead of a {@link TermRangeQuery} one can use a + * {@link TermRangeFilter}. *
Normally the buffers are allocated by the JVM. When using for example * {@link org.apache.lucene.store.MMapDirectory} the buffering is left to * the operating system. diff --git a/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java b/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java index 146178abc25..a558f2cedbb 100644 --- a/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java +++ b/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java @@ -29,31 +29,32 @@ import java.text.Collator; * Either or both endpoints may be open. Open endpoints may not be exclusive * (you can't select all but the first or last term without explicitly specifying the term to exclude.) * - * @deprecated Please use {@link RangeQuery}, and call - * {@link RangeQuery#setConstantScoreRewrite}, instead. + * @deprecated Use {@link TermRangeQuery} for term ranges or + * {@link NumericRangeQuery} for numeric ranges instead. + * This class will be removed in Lucene 3.0. * @version $Id$ */ -public class ConstantScoreRangeQuery extends RangeQuery +public class ConstantScoreRangeQuery extends TermRangeQuery { public ConstantScoreRangeQuery(String fieldName, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper) { super(fieldName, lowerVal, upperVal, includeLower, includeUpper); - this.constantScoreRewrite = true; + setConstantScoreRewrite(true); } public ConstantScoreRangeQuery(String fieldName, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper, Collator collator) { super(fieldName, lowerVal, upperVal, includeLower, includeUpper, collator); - this.constantScoreRewrite = true; + setConstantScoreRewrite(true); } public String getLowerVal() { - return getLowerTermText(); + return getLowerTerm(); } public String getUpperVal() { - return getUpperTermText(); + return getUpperTerm(); } } diff --git a/src/java/org/apache/lucene/search/FieldCacheRangeFilter.java b/src/java/org/apache/lucene/search/FieldCacheRangeFilter.java index 6efac81e905..9d80af5775a 100644 --- a/src/java/org/apache/lucene/search/FieldCacheRangeFilter.java +++ b/src/java/org/apache/lucene/search/FieldCacheRangeFilter.java @@ -31,9 +31,9 @@ import org.apache.lucene.document.NumericField; // for javadocs * even if the range itself changes. * *
This means that FieldCacheRangeFilter is much faster (sometimes more than 100x as fast) - * as building a {@link RangeFilter} (or {@link ConstantScoreRangeQuery} on a {@link RangeFilter}) + * as building a {@link TermRangeFilter} (or {@link ConstantScoreRangeQuery} on a {@link TermRangeFilter}) * for each query, if using a {@link #newStringRange}. However, if the range never changes it - * is slower (around 2x as slow) than building a CachingWrapperFilter on top of a single RangeFilter. + * is slower (around 2x as slow) than building a CachingWrapperFilter on top of a single TermRangeFilter. * * For numeric data types, this filter may be significantly faster than {@link NumericRangeFilter}. * Furthermore, it does not need the numeric values encoded by {@link NumericField}. But diff --git a/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java b/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java index 2e016a9f931..35b432cd6fb 100644 --- a/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java +++ b/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java @@ -34,7 +34,7 @@ import java.util.BitSet; * be used by itself. Normally you subclass it to provide a Filter * counterpart for a {@link MultiTermQuery} subclass. *
- * For example, {@link RangeFilter} and {@link PrefixFilter} extend
+ * For example, {@link TermRangeFilter} and {@link PrefixFilter} extend
* MultiTermQueryWrapperFilter
.
* This class also provides the functionality behind
* {@link MultiTermQuery#getFilter}, this is why it is not abstract.
diff --git a/src/java/org/apache/lucene/search/Query.java b/src/java/org/apache/lucene/search/Query.java
index 6e08fde4bbe..a76af317073 100644
--- a/src/java/org/apache/lucene/search/Query.java
+++ b/src/java/org/apache/lucene/search/Query.java
@@ -36,7 +36,8 @@ import org.apache.lucene.index.IndexReader;
A parser for queries is contained in: @@ -146,7 +147,7 @@ public abstract class Query implements java.io.Serializable, Cloneable { * correspondence with queries). This is an optimization of the OR of * all queries. We handle the common optimization cases of equal * queries and overlapping clauses of boolean OR queries (as generated - * by MultiTermQuery.rewrite() and RangeQuery.rewrite()). + * by MultiTermQuery.rewrite()). * Be careful overriding this method as queries[0] determines which * method will be called and is not necessarily of the same type as * the other queries. diff --git a/src/java/org/apache/lucene/search/QueryWrapperFilter.java b/src/java/org/apache/lucene/search/QueryWrapperFilter.java index d697482a419..c855a7f0bcf 100644 --- a/src/java/org/apache/lucene/search/QueryWrapperFilter.java +++ b/src/java/org/apache/lucene/search/QueryWrapperFilter.java @@ -26,10 +26,10 @@ import org.apache.lucene.index.IndexReader; * Constrains search results to only match those which also match a provided * query. * - *
This could be used, for example, with a {@link RangeQuery} on a suitably + *
This could be used, for example, with a {@link TermRangeQuery} on a suitably * formatted date field to implement date filtering. One could re-use a single * QueryFilter that matches, e.g., only documents modified within the last - * week. The QueryFilter and RangeQuery would only need to be reconstructed + * week. The QueryFilter and TermRangeQuery would only need to be reconstructed * once per day. * * @version $Id:$ 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 97b68461d11..00000000000 --- a/src/java/org/apache/lucene/search/RangeFilter.java +++ /dev/null @@ -1,88 +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. - * - *
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. - * - *
If you construct a large number of range filters with different ranges but on the
- * same field, {@link FieldCacheRangeFilter} may have significantly better performance.
- */
-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 RangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper));
- }
-
- /**
- * WARNING: Using this constructor and supplying a non-null
- * value in the collator
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 RangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper, collator));
- }
-
- /**
- * Constructs a filter for field fieldName
matching
- * less than or equal to upperTerm
.
- */
- public static RangeFilter Less(String fieldName, String upperTerm) {
- return new RangeFilter(fieldName, null, upperTerm, false, true);
- }
-
- /**
- * Constructs a filter for field fieldName
matching
- * greater than or equal to lowerTerm
.
- */
- 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/TermRangeFilter.java b/src/java/org/apache/lucene/search/TermRangeFilter.java
new file mode 100644
index 00000000000..e5571933b2e
--- /dev/null
+++ b/src/java/org/apache/lucene/search/TermRangeFilter.java
@@ -0,0 +1,88 @@
+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.
+ *
+ *
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. + * + *
If you construct a large number of range filters with different ranges but on the
+ * same field, {@link FieldCacheRangeFilter} may have significantly better performance.
+ */
+public class TermRangeFilter 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 TermRangeFilter(String fieldName, String lowerTerm, String upperTerm,
+ boolean includeLower, boolean includeUpper) {
+ super(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper));
+ }
+
+ /**
+ * WARNING: Using this constructor and supplying a non-null
+ * value in the collator
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 TermRangeFilter(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 fieldName
matching
+ * less than or equal to upperTerm
.
+ */
+ public static TermRangeFilter Less(String fieldName, String upperTerm) {
+ return new TermRangeFilter(fieldName, null, upperTerm, false, true);
+ }
+
+ /**
+ * Constructs a filter for field fieldName
matching
+ * greater than or equal to lowerTerm
.
+ */
+ public static TermRangeFilter More(String fieldName, String lowerTerm) {
+ return new TermRangeFilter(fieldName, lowerTerm, null, true, false);
+ }
+}
diff --git a/src/java/org/apache/lucene/search/RangeQuery.java b/src/java/org/apache/lucene/search/TermRangeQuery.java
similarity index 68%
rename from src/java/org/apache/lucene/search/RangeQuery.java
rename to src/java/org/apache/lucene/search/TermRangeQuery.java
index 5db295911d0..4ebae13cdb2 100644
--- a/src/java/org/apache/lucene/search/RangeQuery.java
+++ b/src/java/org/apache/lucene/search/TermRangeQuery.java
@@ -22,21 +22,23 @@ import java.text.Collator;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.util.ToStringUtils;
/**
- * A Query that matches documents within an exclusive range.
+ * A Query that matches documents within an exclusive range of terms.
*
*
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. * - *
See {@link MultiTermQuery#setConstantScoreRewrite} for the tradeoffs between + *
This query is in constant score mode per default.
+ * See {@link MultiTermQuery#setConstantScoreRewrite} for the tradeoffs between
* enabling and disabling constantScoreRewrite mode.
*/
-public class RangeQuery extends MultiTermQuery {
- private Term lowerTerm;
- private Term upperTerm;
+public class TermRangeQuery extends MultiTermQuery {
+ private String lowerTerm;
+ private String upperTerm;
private Collator collator;
private String field;
private boolean includeLower;
@@ -65,8 +67,8 @@ public class RangeQuery extends MultiTermQuery {
* If true, the upperTerm
is
* included in the range.
*/
- public RangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
- init(new Term(field, lowerTerm), new Term(field, upperTerm), includeLower, includeUpper, null);
+ public TermRangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
+ this(field, lowerTerm, upperTerm, includeLower, includeUpper, null);
}
/** Constructs a query selecting all terms greater/equal than
@@ -99,59 +101,27 @@ public class RangeQuery extends MultiTermQuery {
* their membership in the range bounded by lowerTerm
and
* upperTerm
.
*/
- public RangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper,
+ public TermRangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper,
Collator collator) {
- init(new Term(field, lowerTerm), new Term(field,upperTerm), includeLower, includeUpper, collator);
- }
-
- /** @deprecated Please use {@link #RangeQuery(String,
- * String, String, boolean, boolean, Collator)} instead */
- public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive,
- Collator collator) {
- init(lowerTerm, upperTerm, inclusive, inclusive, collator);
- }
-
- /** @deprecated Please use {@link #RangeQuery(String,
- * String, String, boolean, boolean)} instead */
- public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive) {
- init(lowerTerm, upperTerm, inclusive, inclusive, null);
- }
-
- private void init(Term lowerTerm, Term upperTerm, boolean includeLower, boolean includeUpper, 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 be for the same field");
-
- if (lowerTerm == null)
- this.field = upperTerm.field();
- else
- this.field = lowerTerm.field();
+ this.field = field;
this.lowerTerm = lowerTerm;
this.upperTerm = upperTerm;
this.includeLower = includeLower;
this.includeUpper = includeUpper;
this.collator = collator;
+ setConstantScoreRewrite(true);
}
-
+
/** Returns the field name for this query */
public String getField() {
return field;
}
-
- /** Returns the lower term of this range query.
- * @deprecated Use {@link #getLowerTermText} instead. */
- public Term getLowerTerm() { return lowerTerm; }
-
- /** Returns the upper term of this range query.
- * @deprecated Use {@link #getUpperTermText} instead. */
- public Term getUpperTerm() { return upperTerm; }
/** Returns the lower value of this range query */
- public String getLowerTermText() { return lowerTerm == null ? null : lowerTerm.text(); }
+ public String getLowerTerm() { return lowerTerm; }
/** Returns the upper value of this range query */
- public String getUpperTermText() { return upperTerm == null ? null : upperTerm.text(); }
+ public String getUpperTerm() { return upperTerm; }
/** Returns true
if the lower endpoint is inclusive */
public boolean includesLower() { return includeLower; }
@@ -159,18 +129,12 @@ public class RangeQuery extends MultiTermQuery {
/** Returns true
if the upper endpoint is inclusive */
public boolean includesUpper() { return includeUpper; }
- /** Returns true
if the range query is inclusive
- * @deprecated Use {@link #includesLower}, {@link #includesUpper} instead.
- */
- public boolean isInclusive() { return includeUpper && includeLower; }
-
/** Returns the collator used to determine range inclusion, if any. */
public Collator getCollator() { return collator; }
protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
- //TODO: when the deprecated 'Term' constructors are removed we can remove these null checks
- return new RangeTermEnum(reader, collator, getField(), lowerTerm == null ? null : lowerTerm.text(),
- upperTerm == null ? null : upperTerm.text(), includeLower, includeUpper);
+ return new TermRangeTermEnum(reader, collator, field, lowerTerm,
+ upperTerm, includeLower, includeUpper);
}
/** Prints a user-readable version of this query. */
@@ -181,14 +145,11 @@ public class RangeQuery extends MultiTermQuery {
buffer.append(":");
}
buffer.append(includeLower ? '[' : '{');
- buffer.append(lowerTerm != null ? lowerTerm.text() : "*");
+ buffer.append(lowerTerm != null ? lowerTerm : "*");
buffer.append(" TO ");
- buffer.append(upperTerm != null ? upperTerm.text() : "*");
+ buffer.append(upperTerm != null ? upperTerm : "*");
buffer.append(includeUpper ? ']' : '}');
- if (getBoost() != 1.0f) {
- buffer.append("^");
- buffer.append(Float.toString(getBoost()));
- }
+ buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
}
@@ -213,7 +174,7 @@ public class RangeQuery extends MultiTermQuery {
return false;
if (getClass() != obj.getClass())
return false;
- RangeQuery other = (RangeQuery) obj;
+ TermRangeQuery other = (TermRangeQuery) obj;
if (collator == null) {
if (other.collator != null)
return false;
diff --git a/src/java/org/apache/lucene/search/RangeTermEnum.java b/src/java/org/apache/lucene/search/TermRangeTermEnum.java
similarity index 96%
rename from src/java/org/apache/lucene/search/RangeTermEnum.java
rename to src/java/org/apache/lucene/search/TermRangeTermEnum.java
index 43581273d19..ebb13c3d364 100644
--- a/src/java/org/apache/lucene/search/RangeTermEnum.java
+++ b/src/java/org/apache/lucene/search/TermRangeTermEnum.java
@@ -30,7 +30,7 @@ import org.apache.lucene.index.Term;
* Term enumerations are always ordered by Term.compareTo(). Each term in
* the enumeration is greater than all that precede it.
*/
-public class RangeTermEnum extends FilteredTermEnum {
+public class TermRangeTermEnum extends FilteredTermEnum {
private Collator collator = null;
private boolean endEnum = false;
@@ -67,14 +67,14 @@ public class RangeTermEnum extends FilteredTermEnum {
*
* @throws IOException
*/
- public RangeTermEnum(IndexReader reader, Collator collator, String field,
+ public TermRangeTermEnum(IndexReader reader, Collator collator, String field,
String lowerTermText, String upperTermText, boolean includeLower, boolean includeUpper) throws IOException {
this.collator = collator;
this.upperTermText = upperTermText;
this.lowerTermText = lowerTermText;
this.includeLower = includeLower;
this.includeUpper = includeUpper;
- this.field = field;
+ this.field = field.intern();
// do a little bit of normalization...
// open ended range queries should always be inclusive.
diff --git a/src/java/org/apache/lucene/search/package.html b/src/java/org/apache/lucene/search/package.html
index 2fdf926507d..f67fbc6ca42 100644
--- a/src/java/org/apache/lucene/search/package.html
+++ b/src/java/org/apache/lucene/search/package.html
@@ -138,11 +138,11 @@ org.apache.lucene.search.Searcher#search(Query,Filter)}.
The - RangeQuery + TermRangeQuery matches all documents that occur in the exclusive range of a lower Term diff --git a/src/test/org/apache/lucene/queryParser/TestQueryParser.java b/src/test/org/apache/lucene/queryParser/TestQueryParser.java index f88e38f9df6..86a246cd748 100644 --- a/src/test/org/apache/lucene/queryParser/TestQueryParser.java +++ b/src/test/org/apache/lucene/queryParser/TestQueryParser.java @@ -50,7 +50,7 @@ import org.apache.lucene.search.MatchAllDocsQuery; 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.ScoreDoc; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; @@ -431,11 +431,11 @@ public class TestQueryParser extends LuceneTestCase { public void testRange() throws Exception { assertQueryEquals("[ a TO z]", null, "[a TO z]"); - assertTrue(((RangeQuery)getQuery("[ a TO z]", null)).getConstantScoreRewrite()); + assertTrue(((TermRangeQuery)getQuery("[ a TO z]", null)).getConstantScoreRewrite()); QueryParser qp = new QueryParser("field", new SimpleAnalyzer()); qp.setConstantScoreRewrite(false); - assertFalse(((RangeQuery)qp.parse("[ a TO z]")).getConstantScoreRewrite()); + assertFalse(((TermRangeQuery)qp.parse("[ a TO z]")).getConstantScoreRewrite()); assertQueryEquals("[ a TO z ]", null, "[a TO z]"); assertQueryEquals("{ a TO z}", null, "{a TO z}"); @@ -481,7 +481,7 @@ public class TestQueryParser extends LuceneTestCase { result = is.search(qp.parse("[ \u0633 TO \u0638 ]"), null, 1000).scoreDocs; assertEquals("The index Term should be included.", 1, result.length); - // Test RangeQuery + // Test TermRangeQuery qp.setConstantScoreRewrite(false); result = is.search(qp.parse("[ \u062F TO \u0698 ]"), null, 1000).scoreDocs; assertEquals("The index Term should not be included.", 0, result.length); diff --git a/src/test/org/apache/lucene/search/TestDateFilter.java b/src/test/org/apache/lucene/search/TestDateFilter.java index 134f5d4bfd2..a5b21a58f24 100644 --- a/src/test/org/apache/lucene/search/TestDateFilter.java +++ b/src/test/org/apache/lucene/search/TestDateFilter.java @@ -66,11 +66,11 @@ public class TestDateFilter // filter that should preserve matches //DateFilter df1 = DateFilter.Before("datefield", now); - RangeFilter df1 = new RangeFilter("datefield", DateTools.timeToString(now - 2000, DateTools.Resolution.MILLISECOND), + TermRangeFilter df1 = new TermRangeFilter("datefield", DateTools.timeToString(now - 2000, DateTools.Resolution.MILLISECOND), DateTools.timeToString(now, DateTools.Resolution.MILLISECOND), false, true); // filter that should discard matches //DateFilter df2 = DateFilter.Before("datefield", now - 999999); - RangeFilter df2 = new RangeFilter("datefield", DateTools.timeToString(0, DateTools.Resolution.MILLISECOND), + TermRangeFilter df2 = new TermRangeFilter("datefield", DateTools.timeToString(0, DateTools.Resolution.MILLISECOND), DateTools.timeToString(now - 2000, DateTools.Resolution.MILLISECOND), true, false); // search something that doesn't exist with DateFilter @@ -127,11 +127,11 @@ public class TestDateFilter // filter that should preserve matches //DateFilter df1 = DateFilter.After("datefield", now); - RangeFilter df1 = new RangeFilter("datefield", DateTools.timeToString(now, DateTools.Resolution.MILLISECOND), + TermRangeFilter df1 = new TermRangeFilter("datefield", DateTools.timeToString(now, DateTools.Resolution.MILLISECOND), DateTools.timeToString(now + 999999, DateTools.Resolution.MILLISECOND), true, false); // filter that should discard matches //DateFilter df2 = DateFilter.After("datefield", now + 999999); - RangeFilter df2 = new RangeFilter("datefield", DateTools.timeToString(now + 999999, DateTools.Resolution.MILLISECOND), + TermRangeFilter df2 = new TermRangeFilter("datefield", DateTools.timeToString(now + 999999, DateTools.Resolution.MILLISECOND), DateTools.timeToString(now + 999999999, DateTools.Resolution.MILLISECOND), false, true); // search something that doesn't exist with DateFilter diff --git a/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java b/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java index afeca137203..a084b416910 100644 --- a/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java +++ b/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java @@ -30,7 +30,7 @@ import org.apache.lucene.document.Field; import org.apache.lucene.store.RAMDirectory; /** - * A basic 'positive' Unit test class for the RangeFilter class. + * A basic 'positive' Unit test class for the FieldCacheRangeFilter class. * *
* NOTE: at the moment, this class only tests for 'positive' results, diff --git a/src/test/org/apache/lucene/search/TestFilteredQuery.java b/src/test/org/apache/lucene/search/TestFilteredQuery.java index 0e1dc729176..e4d62008d63 100644 --- a/src/test/org/apache/lucene/search/TestFilteredQuery.java +++ b/src/test/org/apache/lucene/search/TestFilteredQuery.java @@ -177,8 +177,8 @@ extends LuceneTestCase { * This tests FilteredQuery's rewrite correctness */ public void testRangeQuery() throws Exception { - RangeQuery rq = new RangeQuery( - new Term("sorter", "b"), new Term("sorter", "d"), true); + TermRangeQuery rq = new TermRangeQuery( + "sorter", "b", "d", true, true); Query filteredquery = new FilteredQuery(rq, filter); ScoreDoc[] hits = searcher.search(filteredquery, null, 1000).scoreDocs; diff --git a/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java b/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java index 182b5b52ef4..8bab8a85a28 100644 --- a/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java +++ b/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java @@ -87,7 +87,7 @@ public class TestMultiTermConstantScore extends BaseTestRangeFilter { /** macro for readability */ public static Query csrq(String f, String l, String h, boolean il, boolean ih) { - RangeQuery query = new RangeQuery(f, l, h, il, ih); + TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih); query.setConstantScoreRewrite(true); return query; } @@ -95,7 +95,7 @@ public class TestMultiTermConstantScore extends BaseTestRangeFilter { /** macro for readability */ public static Query csrq(String f, String l, String h, boolean il, boolean ih, Collator c) { - RangeQuery query = new RangeQuery(f, l, h, il, ih, c); + TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih, c); query.setConstantScoreRewrite(true); return query; } @@ -220,10 +220,10 @@ public class TestMultiTermConstantScore extends BaseTestRangeFilter { IndexReader reader = IndexReader.open(small); IndexSearcher search = new IndexSearcher(reader); - // first do a regular RangeQuery which uses term expansion so + // first do a regular TermRangeQuery which uses term expansion so // docs with more terms in range get higher scores - Query rq = new RangeQuery(new Term("data", "1"), new Term("data", "4"), T); + Query rq = new TermRangeQuery("data", "1", "4", T, T); ScoreDoc[] expected = search.search(rq, null, 1000).scoreDocs; int numHits = expected.length; diff --git a/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java b/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java index 6c4c11353b1..5c928dc3b30 100644 --- a/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java +++ b/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java @@ -226,38 +226,38 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { } // test inclusive range NumericRangeQuery tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), true, true); - RangeQuery cq=new RangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), true, true); + TermRangeQuery cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), true, true); cq.setConstantScoreRewrite(true); TopDocs tTopDocs = searcher.search(tq, 1); TopDocs cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test exclusive range tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), false, false); - cq=new RangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), false, false); + cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), false, false); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test left exclusive range tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), false, true); - cq=new RangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), false, true); + cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), false, true); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test right exclusive range tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), true, false); - cq=new RangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), true, false); + cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), true, false); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); } diff --git a/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java b/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java index 1415b0ccd08..bec0a35ac1b 100644 --- a/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java +++ b/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java @@ -226,38 +226,38 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { } // test inclusive range NumericRangeQuery tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), true, true); - RangeQuery cq=new RangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), true, true); + TermRangeQuery cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), true, true); cq.setConstantScoreRewrite(true); TopDocs tTopDocs = searcher.search(tq, 1); TopDocs cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test exclusive range tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), false, false); - cq=new RangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), false, false); + cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), false, false); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test left exclusive range tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), false, true); - cq=new RangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), false, true); + cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), false, true); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test right exclusive range tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), true, false); - cq=new RangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), true, false); + cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), true, false); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); } diff --git a/src/test/org/apache/lucene/search/TestRangeFilter.java b/src/test/org/apache/lucene/search/TestTermRangeFilter.java similarity index 65% rename from src/test/org/apache/lucene/search/TestRangeFilter.java rename to src/test/org/apache/lucene/search/TestTermRangeFilter.java index 18ce8682d88..0a9fe3cf632 100644 --- a/src/test/org/apache/lucene/search/TestRangeFilter.java +++ b/src/test/org/apache/lucene/search/TestTermRangeFilter.java @@ -30,7 +30,7 @@ import org.apache.lucene.document.Field; import org.apache.lucene.store.RAMDirectory; /** - * A basic 'positive' Unit test class for the RangeFilter class. + * A basic 'positive' Unit test class for the TermRangeFilter class. * *
* NOTE: at the moment, this class only tests for 'positive' results, @@ -38,12 +38,12 @@ import org.apache.lucene.store.RAMDirectory; * nor does it adequately test 'negative' results. It also does not test * that garbage in results in an Exception. */ -public class TestRangeFilter extends BaseTestRangeFilter { +public class TestTermRangeFilter extends BaseTestRangeFilter { - public TestRangeFilter(String name) { + public TestTermRangeFilter(String name) { super(name); } - public TestRangeFilter() { + public TestTermRangeFilter() { super(); } @@ -67,64 +67,64 @@ public class TestRangeFilter extends BaseTestRangeFilter { // test id, bounded on both ends - result = search.search(q,new RangeFilter("id",minIP,maxIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,T), numDocs).scoreDocs; assertEquals("find all", numDocs, result.length); - result = search.search(q,new RangeFilter("id",minIP,maxIP,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,F), numDocs).scoreDocs; assertEquals("all but last", numDocs-1, result.length); - result = search.search(q,new RangeFilter("id",minIP,maxIP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,T), numDocs).scoreDocs; assertEquals("all but first", numDocs-1, result.length); - result = search.search(q,new RangeFilter("id",minIP,maxIP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,F), numDocs).scoreDocs; assertEquals("all but ends", numDocs-2, result.length); - result = search.search(q,new RangeFilter("id",medIP,maxIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,T), numDocs).scoreDocs; assertEquals("med and up", 1+ maxId-medId, result.length); - result = search.search(q,new RangeFilter("id",minIP,medIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,medIP,T,T), numDocs).scoreDocs; assertEquals("up to med", 1+ medId-minId, result.length); // unbounded id - result = search.search(q,new RangeFilter("id",minIP,null,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,null,T,F), numDocs).scoreDocs; assertEquals("min and up", numDocs, result.length); - result = search.search(q,new RangeFilter("id",null,maxIP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",null,maxIP,F,T), numDocs).scoreDocs; assertEquals("max and down", numDocs, result.length); - result = search.search(q,new RangeFilter("id",minIP,null,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,null,F,F), numDocs).scoreDocs; assertEquals("not min, but up", numDocs-1, result.length); - result = search.search(q,new RangeFilter("id",null,maxIP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",null,maxIP,F,F), numDocs).scoreDocs; assertEquals("not max, but down", numDocs-1, result.length); - result = search.search(q,new RangeFilter("id",medIP,maxIP,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,F), numDocs).scoreDocs; assertEquals("med and up, not max", maxId-medId, result.length); - result = search.search(q,new RangeFilter("id",minIP,medIP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,medIP,F,T), numDocs).scoreDocs; assertEquals("not min, up to med", medId-minId, result.length); // very small sets - result = search.search(q,new RangeFilter("id",minIP,minIP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,minIP,F,F), numDocs).scoreDocs; assertEquals("min,min,F,F", 0, result.length); - result = search.search(q,new RangeFilter("id",medIP,medIP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",medIP,medIP,F,F), numDocs).scoreDocs; assertEquals("med,med,F,F", 0, result.length); - result = search.search(q,new RangeFilter("id",maxIP,maxIP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",maxIP,maxIP,F,F), numDocs).scoreDocs; assertEquals("max,max,F,F", 0, result.length); - result = search.search(q,new RangeFilter("id",minIP,minIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,minIP,T,T), numDocs).scoreDocs; assertEquals("min,min,T,T", 1, result.length); - result = search.search(q,new RangeFilter("id",null,minIP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",null,minIP,F,T), numDocs).scoreDocs; assertEquals("nul,min,F,T", 1, result.length); - result = search.search(q,new RangeFilter("id",maxIP,maxIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",maxIP,maxIP,T,T), numDocs).scoreDocs; assertEquals("max,max,T,T", 1, result.length); - result = search.search(q,new RangeFilter("id",maxIP,null,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",maxIP,null,T,F), numDocs).scoreDocs; assertEquals("max,nul,T,T", 1, result.length); - result = search.search(q,new RangeFilter("id",medIP,medIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",medIP,medIP,T,T), numDocs).scoreDocs; assertEquals("med,med,T,T", 1, result.length); } @@ -151,64 +151,64 @@ public class TestRangeFilter extends BaseTestRangeFilter { // test id, bounded on both ends - result = search.search(q,new RangeFilter("id",minIP,maxIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,T,c)); assertEquals("find all", numDocs, result.length()); - result = search.search(q,new RangeFilter("id",minIP,maxIP,T,F,c)); + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,F,c)); assertEquals("all but last", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("id",minIP,maxIP,F,T,c)); + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,T,c)); assertEquals("all but first", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("id",minIP,maxIP,F,F,c)); + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,F,c)); assertEquals("all but ends", numDocs-2, result.length()); - result = search.search(q,new RangeFilter("id",medIP,maxIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,T,c)); assertEquals("med and up", 1+ maxId-medId, result.length()); - result = search.search(q,new RangeFilter("id",minIP,medIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",minIP,medIP,T,T,c)); assertEquals("up to med", 1+ medId-minId, result.length()); // unbounded id - result = search.search(q,new RangeFilter("id",minIP,null,T,F,c)); + result = search.search(q,new TermRangeFilter("id",minIP,null,T,F,c)); assertEquals("min and up", numDocs, result.length()); - result = search.search(q,new RangeFilter("id",null,maxIP,F,T,c)); + result = search.search(q,new TermRangeFilter("id",null,maxIP,F,T,c)); assertEquals("max and down", numDocs, result.length()); - result = search.search(q,new RangeFilter("id",minIP,null,F,F,c)); + result = search.search(q,new TermRangeFilter("id",minIP,null,F,F,c)); assertEquals("not min, but up", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("id",null,maxIP,F,F,c)); + result = search.search(q,new TermRangeFilter("id",null,maxIP,F,F,c)); assertEquals("not max, but down", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("id",medIP,maxIP,T,F,c)); + result = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,F,c)); assertEquals("med and up, not max", maxId-medId, result.length()); - result = search.search(q,new RangeFilter("id",minIP,medIP,F,T,c)); + result = search.search(q,new TermRangeFilter("id",minIP,medIP,F,T,c)); assertEquals("not min, up to med", medId-minId, result.length()); // very small sets - result = search.search(q,new RangeFilter("id",minIP,minIP,F,F,c)); + result = search.search(q,new TermRangeFilter("id",minIP,minIP,F,F,c)); assertEquals("min,min,F,F", 0, result.length()); - result = search.search(q,new RangeFilter("id",medIP,medIP,F,F,c)); + result = search.search(q,new TermRangeFilter("id",medIP,medIP,F,F,c)); assertEquals("med,med,F,F", 0, result.length()); - result = search.search(q,new RangeFilter("id",maxIP,maxIP,F,F,c)); + result = search.search(q,new TermRangeFilter("id",maxIP,maxIP,F,F,c)); assertEquals("max,max,F,F", 0, result.length()); - result = search.search(q,new RangeFilter("id",minIP,minIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",minIP,minIP,T,T,c)); assertEquals("min,min,T,T", 1, result.length()); - result = search.search(q,new RangeFilter("id",null,minIP,F,T,c)); + result = search.search(q,new TermRangeFilter("id",null,minIP,F,T,c)); assertEquals("nul,min,F,T", 1, result.length()); - result = search.search(q,new RangeFilter("id",maxIP,maxIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",maxIP,maxIP,T,T,c)); assertEquals("max,max,T,T", 1, result.length()); - result = search.search(q,new RangeFilter("id",maxIP,null,T,F,c)); + result = search.search(q,new TermRangeFilter("id",maxIP,null,T,F,c)); assertEquals("max,nul,T,T", 1, result.length()); - result = search.search(q,new RangeFilter("id",medIP,medIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",medIP,medIP,T,T,c)); assertEquals("med,med,T,T", 1, result.length()); } @@ -229,47 +229,47 @@ public class TestRangeFilter extends BaseTestRangeFilter { // test extremes, bounded on both ends - result = search.search(q,new RangeFilter("rand",minRP,maxRP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,T), numDocs).scoreDocs; assertEquals("find all", numDocs, result.length); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,F), numDocs).scoreDocs; assertEquals("all but biggest", numDocs-1, result.length); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,T), numDocs).scoreDocs; assertEquals("all but smallest", numDocs-1, result.length); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,F), numDocs).scoreDocs; assertEquals("all but extremes", numDocs-2, result.length); // unbounded - result = search.search(q,new RangeFilter("rand",minRP,null,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,null,T,F), numDocs).scoreDocs; assertEquals("smallest and up", numDocs, result.length); - result = search.search(q,new RangeFilter("rand",null,maxRP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",null,maxRP,F,T), numDocs).scoreDocs; assertEquals("biggest and down", numDocs, result.length); - result = search.search(q,new RangeFilter("rand",minRP,null,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,null,F,F), numDocs).scoreDocs; assertEquals("not smallest, but up", numDocs-1, result.length); - result = search.search(q,new RangeFilter("rand",null,maxRP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",null,maxRP,F,F), numDocs).scoreDocs; assertEquals("not biggest, but down", numDocs-1, result.length); // very small sets - result = search.search(q,new RangeFilter("rand",minRP,minRP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,minRP,F,F), numDocs).scoreDocs; assertEquals("min,min,F,F", 0, result.length); - result = search.search(q,new RangeFilter("rand",maxRP,maxRP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,F,F), numDocs).scoreDocs; assertEquals("max,max,F,F", 0, result.length); - result = search.search(q,new RangeFilter("rand",minRP,minRP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,minRP,T,T), numDocs).scoreDocs; assertEquals("min,min,T,T", 1, result.length); - result = search.search(q,new RangeFilter("rand",null,minRP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",null,minRP,F,T), numDocs).scoreDocs; assertEquals("nul,min,F,T", 1, result.length); - result = search.search(q,new RangeFilter("rand",maxRP,maxRP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,T,T), numDocs).scoreDocs; assertEquals("max,max,T,T", 1, result.length); - result = search.search(q,new RangeFilter("rand",maxRP,null,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",maxRP,null,T,F), numDocs).scoreDocs; assertEquals("max,nul,T,T", 1, result.length); } @@ -294,47 +294,47 @@ public class TestRangeFilter extends BaseTestRangeFilter { // test extremes, bounded on both ends - result = search.search(q,new RangeFilter("rand",minRP,maxRP,T,T,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,T,c)); assertEquals("find all", numDocs, result.length()); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,T,F,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,F,c)); assertEquals("all but biggest", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,F,T,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,T,c)); assertEquals("all but smallest", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,F,F,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,F,c)); assertEquals("all but extremes", numDocs-2, result.length()); // unbounded - result = search.search(q,new RangeFilter("rand",minRP,null,T,F,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,null,T,F,c)); assertEquals("smallest and up", numDocs, result.length()); - result = search.search(q,new RangeFilter("rand",null,maxRP,F,T,c)); + result = search.search(q,new TermRangeFilter("rand",null,maxRP,F,T,c)); assertEquals("biggest and down", numDocs, result.length()); - result = search.search(q,new RangeFilter("rand",minRP,null,F,F,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,null,F,F,c)); assertEquals("not smallest, but up", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("rand",null,maxRP,F,F,c)); + result = search.search(q,new TermRangeFilter("rand",null,maxRP,F,F,c)); assertEquals("not biggest, but down", numDocs-1, result.length()); // very small sets - result = search.search(q,new RangeFilter("rand",minRP,minRP,F,F,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,minRP,F,F,c)); assertEquals("min,min,F,F", 0, result.length()); - result = search.search(q,new RangeFilter("rand",maxRP,maxRP,F,F,c)); + result = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,F,F,c)); assertEquals("max,max,F,F", 0, result.length()); - result = search.search(q,new RangeFilter("rand",minRP,minRP,T,T,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,minRP,T,T,c)); assertEquals("min,min,T,T", 1, result.length()); - result = search.search(q,new RangeFilter("rand",null,minRP,F,T,c)); + result = search.search(q,new TermRangeFilter("rand",null,minRP,F,T,c)); assertEquals("nul,min,F,T", 1, result.length()); - result = search.search(q,new RangeFilter("rand",maxRP,maxRP,T,T,c)); + result = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,T,T,c)); assertEquals("max,max,T,T", 1, result.length()); - result = search.search(q,new RangeFilter("rand",maxRP,null,T,F,c)); + result = search.search(q,new TermRangeFilter("rand",maxRP,null,T,F,c)); assertEquals("max,nul,T,T", 1, result.length()); } @@ -365,14 +365,14 @@ public class TestRangeFilter extends BaseTestRangeFilter { // 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 RangeFilter with a Farsi + // index Term below should NOT be returned by a TermRangeFilter with a Farsi // Collator (or an Arabic one for the case when Farsi is not supported). Hits result = search.search - (q, new RangeFilter("content", "\u062F", "\u0698", T, T, collator)); + (q, new TermRangeFilter("content", "\u062F", "\u0698", T, T, collator)); assertEquals("The index Term should not be included.", 0, result.length()); result = search.search - (q, new RangeFilter("content", "\u0633", "\u0638", T, T, collator)); + (q, new TermRangeFilter("content", "\u0633", "\u0638", T, T, collator)); assertEquals("The index Term should be included.", 1, result.length()); search.close(); } @@ -403,17 +403,17 @@ public class TestRangeFilter extends BaseTestRangeFilter { Query q = new TermQuery(new Term("body","body")); Collator collator = Collator.getInstance(new Locale("da", "dk")); - Query query = new RangeQuery + Query query = new TermRangeQuery ("content", "H\u00D8T", "MAND", false, false, collator); // Unicode order would not include "H\u00C5T" in [ "H\u00D8T", "MAND" ], // but Danish collation does. Hits result = search.search - (q, new RangeFilter("content", "H\u00D8T", "MAND", F, F, collator)); + (q, new TermRangeFilter("content", "H\u00D8T", "MAND", F, F, collator)); assertEquals("The index Term should be included.", 1, result.length()); result = search.search - (q, new RangeFilter("content", "H\u00C5T", "MAND", F, F, collator)); + (q, new TermRangeFilter("content", "H\u00C5T", "MAND", F, F, collator)); assertEquals ("The index Term should not be included.", 0, result.length()); search.close(); diff --git a/src/test/org/apache/lucene/search/TestRangeQuery.java b/src/test/org/apache/lucene/search/TestTermRangeQuery.java similarity index 87% rename from src/test/org/apache/lucene/search/TestRangeQuery.java rename to src/test/org/apache/lucene/search/TestTermRangeQuery.java index 17766d589ce..383a71581a6 100644 --- a/src/test/org/apache/lucene/search/TestRangeQuery.java +++ b/src/test/org/apache/lucene/search/TestTermRangeQuery.java @@ -35,7 +35,7 @@ import java.util.Locale; import java.text.Collator; -public class TestRangeQuery extends LuceneTestCase { +public class TestTermRangeQuery extends LuceneTestCase { private int docCount = 0; private RAMDirectory dir; @@ -46,7 +46,7 @@ public class TestRangeQuery extends LuceneTestCase { } public void testExclusive() throws Exception { - Query query = new RangeQuery("content", "A", "C", false, false); + Query query = new TermRangeQuery("content", "A", "C", false, false); initializeIndex(new String[] {"A", "B", "C", "D"}); IndexSearcher searcher = new IndexSearcher(dir); ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; @@ -84,7 +84,7 @@ public class TestRangeQuery extends LuceneTestCase { } public void testInclusive() throws Exception { - Query query = new RangeQuery("content", "A", "C", true, true); + Query query = new TermRangeQuery("content", "A", "C", true, true); initializeIndex(new String[]{"A", "B", "C", "D"}); IndexSearcher searcher = new IndexSearcher(dir); @@ -106,10 +106,10 @@ public class TestRangeQuery extends LuceneTestCase { } public void testEqualsHashcode() { - Query query = new RangeQuery("content", "A", "C", true, true); + Query query = new TermRangeQuery("content", "A", "C", true, true); query.setBoost(1.0f); - Query other = new RangeQuery("content", "A", "C", true, true); + Query other = new TermRangeQuery("content", "A", "C", true, true); other.setBoost(1.0f); assertEquals("query equals itself is true", query, query); @@ -119,40 +119,40 @@ public class TestRangeQuery extends LuceneTestCase { other.setBoost(2.0f); assertFalse("Different boost queries are not equal", query.equals(other)); - other = new RangeQuery("notcontent", "A", "C", true, true); + other = new TermRangeQuery("notcontent", "A", "C", true, true); assertFalse("Different fields are not equal", query.equals(other)); - other = new RangeQuery("content", "X", "C", true, true); + other = new TermRangeQuery("content", "X", "C", true, true); assertFalse("Different lower terms are not equal", query.equals(other)); - other = new RangeQuery("content", "A", "Z", true, true); + other = new TermRangeQuery("content", "A", "Z", true, true); assertFalse("Different upper terms are not equal", query.equals(other)); - query = new RangeQuery("content", null, "C", true, true); - other = new RangeQuery("content", null, "C", true, true); + query = new TermRangeQuery("content", null, "C", true, true); + other = new TermRangeQuery("content", null, "C", true, true); assertEquals("equivalent queries with null lowerterms are equal()", query, other); assertEquals("hashcode must return same value when equals is true", query.hashCode(), other.hashCode()); - query = new RangeQuery("content", "C", null, true, true); - other = new RangeQuery("content", "C", null, true, true); + query = new TermRangeQuery("content", "C", null, true, true); + other = new TermRangeQuery("content", "C", null, true, true); assertEquals("equivalent queries with null upperterms are equal()", query, other); assertEquals("hashcode returns same value", query.hashCode(), other.hashCode()); - query = new RangeQuery("content", null, "C", true, true); - other = new RangeQuery("content", "C", null, true, true); + query = new TermRangeQuery("content", null, "C", true, true); + other = new TermRangeQuery("content", "C", null, true, true); assertFalse("queries with different upper and lower terms are not equal", query.equals(other)); - query = new RangeQuery("content", "A", "C", false, false); - other = new RangeQuery("content", "A", "C", true, true); + query = new TermRangeQuery("content", "A", "C", false, false); + other = new TermRangeQuery("content", "A", "C", true, true); assertFalse("queries with different inclusive are not equal", query.equals(other)); - query = new RangeQuery("content", "A", "C", false, false); - other = new RangeQuery("content", "A", "C", false, false, Collator.getInstance()); + query = new TermRangeQuery("content", "A", "C", false, false); + other = new TermRangeQuery("content", "A", "C", false, false, Collator.getInstance()); assertFalse("a query with a collator is not equal to one without", query.equals(other)); } public void testExclusiveCollating() throws Exception { - Query query = new RangeQuery("content", "A", "C", false, false, Collator.getInstance(Locale.ENGLISH)); + Query query = new TermRangeQuery("content", "A", "C", false, false, Collator.getInstance(Locale.ENGLISH)); initializeIndex(new String[] {"A", "B", "C", "D"}); IndexSearcher searcher = new IndexSearcher(dir); ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; @@ -173,7 +173,7 @@ public class TestRangeQuery extends LuceneTestCase { } public void testInclusiveCollating() throws Exception { - Query query = new RangeQuery("content", "A", "C",true, true, Collator.getInstance(Locale.ENGLISH)); + Query query = new TermRangeQuery("content", "A", "C",true, true, Collator.getInstance(Locale.ENGLISH)); initializeIndex(new String[]{"A", "B", "C", "D"}); IndexSearcher searcher = new IndexSearcher(dir); @@ -199,17 +199,17 @@ public class TestRangeQuery extends LuceneTestCase { // RuleBasedCollator. However, the Arabic Locale seems to order the Farsi // characters properly. Collator collator = Collator.getInstance(new Locale("ar")); - Query query = new RangeQuery("content", "\u062F", "\u0698", true, true, collator); + Query query = new TermRangeQuery("content", "\u062F", "\u0698", true, true, collator); // 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 RangeQuery with a Farsi + // 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). initializeIndex(new String[]{ "\u0633\u0627\u0628"}); IndexSearcher searcher = new IndexSearcher(dir); ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("The index Term should not be included.", 0, hits.length); - query = new RangeQuery("content", "\u0633", "\u0638",true, true, collator); + query = new TermRangeQuery("content", "\u0633", "\u0638",true, true, collator); hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("The index Term should be included.", 1, hits.length); searcher.close(); @@ -220,7 +220,7 @@ public class TestRangeQuery extends LuceneTestCase { // Danish collation orders the words below in the given order (example taken // from TestSort.testInternationalSort() ). String[] words = { "H\u00D8T", "H\u00C5T", "MAND" }; - Query query = new RangeQuery("content", "H\u00D8T", "MAND", false, false, collator); + Query query = new TermRangeQuery("content", "H\u00D8T", "MAND", false, false, collator); // Unicode order would not include "H\u00C5T" in [ "H\u00D8T", "MAND" ], // but Danish collation does. @@ -229,7 +229,7 @@ public class TestRangeQuery extends LuceneTestCase { ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("The index Term should be included.", 1, hits.length); - query = new RangeQuery("content", "H\u00C5T", "MAND", false, false, collator); + query = new TermRangeQuery("content", "H\u00C5T", "MAND", false, false, collator); hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("The index Term should not be included.", 0, hits.length); searcher.close(); @@ -315,9 +315,8 @@ public class TestRangeQuery extends LuceneTestCase { public void testExclusiveLowerNull() throws Exception { Analyzer analyzer = new SingleCharAnalyzer(); //http://issues.apache.org/jira/browse/LUCENE-38 - Query query = new RangeQuery(null, - new Term("content", "C"), - false); + Query query = new TermRangeQuery("content", null, "C", + false, false); initializeIndex(new String[] {"A", "B", "", "C", "D"}, analyzer); IndexSearcher searcher = new IndexSearcher(dir); Hits hits = searcher.search(query); @@ -349,9 +348,7 @@ public class TestRangeQuery extends LuceneTestCase { public void testInclusiveLowerNull() throws Exception { //http://issues.apache.org/jira/browse/LUCENE-38 Analyzer analyzer = new SingleCharAnalyzer(); - Query query = new RangeQuery(null, - new Term("content", "C"), - true); + Query query = new TermRangeQuery("content", null, "C", true, true); initializeIndex(new String[]{"A", "B", "","C", "D"}, analyzer); IndexSearcher searcher = new IndexSearcher(dir); Hits hits = searcher.search(query);