LUCENE-1713, LUCENE-1673: For completeness, add some getter methods to TermRangeFilter, to be similar like TermRangeQuery and NumericRangeFilter.

This also unifies the hashCode and equals methods in this family of queries. It also fixes a bug in hashCode and equals of NumericRangeQuery, missing the constantScoreRewrite property.
TermRangeTermEnum was changed to have a consistent ctor with TermRangeQuery.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@791263 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-07-05 16:01:52 +00:00
parent 9789089343
commit fc44f0dc3c
4 changed files with 33 additions and 17 deletions

View File

@ -227,7 +227,8 @@ public final class NumericRangeQuery extends MultiTermQuery {
//@Override
public final boolean equals(final Object o) {
if (o==this) return true;
if (o==null) return false;
if (!super.equals(o))
return false;
if (o instanceof NumericRangeQuery) {
final NumericRangeQuery q=(NumericRangeQuery)o;
return (
@ -236,8 +237,7 @@ public final class NumericRangeQuery extends MultiTermQuery {
(q.max == null ? max == null : q.max.equals(max)) &&
minInclusive == q.minInclusive &&
maxInclusive == q.maxInclusive &&
precisionStep == q.precisionStep &&
getBoost() == q.getBoost()
precisionStep == q.precisionStep
);
}
return false;
@ -245,11 +245,11 @@ public final class NumericRangeQuery extends MultiTermQuery {
//@Override
public final int hashCode() {
int hash = Float.floatToIntBits(getBoost()) ^ field.hashCode();
hash += precisionStep^0x64365465;
int hash = super.hashCode();
hash += field.hashCode()^0x4565fd66 + precisionStep^0x64365465;
if (min != null) hash += min.hashCode()^0x14fa55fb;
if (max != null) hash += max.hashCode()^0x733fa5fe;
return hash+
return hash +
(Boolean.valueOf(minInclusive).hashCode()^0x14fa55fb)+
(Boolean.valueOf(maxInclusive).hashCode()^0x733fa5fe);
}

View File

@ -85,4 +85,22 @@ public class TermRangeFilter extends MultiTermQueryWrapperFilter {
public static TermRangeFilter More(String fieldName, String lowerTerm) {
return new TermRangeFilter(fieldName, lowerTerm, null, true, false);
}
/** Returns the field name for this filter */
public String getField() { return ((TermRangeQuery) query).getField(); }
/** Returns the lower value of this range filter */
public String getLowerTerm() { return ((TermRangeQuery) query).getLowerTerm(); }
/** Returns the upper value of this range filter */
public String getUpperTerm() { return ((TermRangeQuery) query).getUpperTerm(); }
/** Returns <code>true</code> if the lower endpoint is inclusive */
public boolean includesLower() { return ((TermRangeQuery) query).includesLower(); }
/** Returns <code>true</code> if the upper endpoint is inclusive */
public boolean includesUpper() { return ((TermRangeQuery) query).includesUpper(); }
/** Returns the collator used to determine range inclusion, if any. */
public Collator getCollator() { return ((TermRangeQuery) query).getCollator(); }
}

View File

@ -113,9 +113,7 @@ public class TermRangeQuery extends MultiTermQuery {
}
/** Returns the field name for this query */
public String getField() {
return field;
}
public String getField() { return field; }
/** Returns the lower value of this range query */
public String getLowerTerm() { return lowerTerm; }
@ -133,8 +131,8 @@ public class TermRangeQuery extends MultiTermQuery {
public Collator getCollator() { return collator; }
protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
return new TermRangeTermEnum(reader, collator, field, lowerTerm,
upperTerm, includeLower, includeUpper);
return new TermRangeTermEnum(reader, field, lowerTerm,
upperTerm, includeLower, includeUpper, collator);
}
/** Prints a user-readable version of this query. */

View File

@ -50,10 +50,6 @@ public class TermRangeTermEnum extends FilteredTermEnum {
* explicitly specifying the term to exclude.)
*
* @param reader
* @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>.
* @param field
* An interned field that holds both lower and upper terms.
* @param lowerTermText
@ -64,11 +60,15 @@ public class TermRangeTermEnum extends FilteredTermEnum {
* If true, the <code>lowerTerm</code> is included in the range.
* @param includeUpper
* If true, the <code>upperTerm</code> is 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>.
*
* @throws IOException
*/
public TermRangeTermEnum(IndexReader reader, Collator collator, String field,
String lowerTermText, String upperTermText, boolean includeLower, boolean includeUpper) throws IOException {
public TermRangeTermEnum(IndexReader reader, String field, String lowerTermText, String upperTermText,
boolean includeLower, boolean includeUpper, Collator collator) throws IOException {
this.collator = collator;
this.upperTermText = upperTermText;
this.lowerTermText = lowerTermText;