FileDocCategorySizeDatePackage
ConstantScoreRangeQuery.javaAPI DocApache Lucene 2.1.05517Wed Feb 14 10:46:40 GMT 2007org.apache.lucene.search

ConstantScoreRangeQuery

public class ConstantScoreRangeQuery extends Query
A range query that returns a constant score equal to its boost for all documents in the range.

It does not have an upper bound on the number of clauses covered in the range.

If an endpoint is null, it is said to be "open". 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.)

author
yonik
version
$Id: ConstantScoreRangeQuery.java 472959 2006-11-09 16:21:50Z yonik $

Fields Summary
private final String
fieldName
private final String
lowerVal
private final String
upperVal
private final boolean
includeLower
private final boolean
includeUpper
Constructors Summary
public ConstantScoreRangeQuery(String fieldName, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper)

    // do a little bit of normalization...
    // open ended range queries should always be inclusive.
    if (lowerVal==null) {
      includeLower=true;
    } else if (includeLower && lowerVal.equals("")) {
      lowerVal=null;
    }
    if (upperVal==null) {
      includeUpper=true;
    }


    this.fieldName = fieldName.intern();  // intern it, just like terms...
    this.lowerVal = lowerVal;
    this.upperVal = upperVal;
    this.includeLower = includeLower;
    this.includeUpper = includeUpper;
  
Methods Summary
public booleanequals(java.lang.Object o)
Returns true if o is equal to this.

        if (this == o) return true;
        if (!(o instanceof ConstantScoreRangeQuery)) return false;
        ConstantScoreRangeQuery other = (ConstantScoreRangeQuery) o;

        if (this.fieldName != other.fieldName  // interned comparison
            || this.includeLower != other.includeLower
            || this.includeUpper != other.includeUpper
           ) { return false; }
        if (this.lowerVal != null ? !this.lowerVal.equals(other.lowerVal) : other.lowerVal != null) return false;
        if (this.upperVal != null ? !this.upperVal.equals(other.upperVal) : other.upperVal != null) return false;
        return this.getBoost() == other.getBoost();
    
public java.lang.StringgetField()
Returns the field name for this query

 return fieldName; 
public java.lang.StringgetLowerVal()
Returns the value of the lower endpoint of this range query, null if open ended

 return lowerVal; 
public java.lang.StringgetUpperVal()
Returns the value of the upper endpoint of this range query, null if open ended

 return upperVal; 
public inthashCode()
Returns a hash code value for this object.

      int h = Float.floatToIntBits(getBoost()) ^ fieldName.hashCode();
      // hashCode of "" is 0, so don't use that for null...
      h ^= lowerVal != null ? lowerVal.hashCode() : 0x965a965a;
      // don't just XOR upperVal with out mixing either it or h, as it will cancel
      // out lowerVal if they are equal.
      h ^= (h << 17) | (h >>> 16);  // a reversible (one to one) 32 bit mapping mix
      h ^= (upperVal != null ? (upperVal.hashCode()) : 0x5a695a69);
      h ^= (includeLower ? 0x665599aa : 0)
         ^ (includeUpper ? 0x99aa5566 : 0);
      return h;
    
public booleanincludesLower()
Returns true if the lower endpoint is inclusive

 return includeLower; 
public booleanincludesUpper()
Returns true if the upper endpoint is inclusive

 return includeUpper; 
public org.apache.lucene.search.Queryrewrite(org.apache.lucene.index.IndexReader reader)

    // Map to RangeFilter semantics which are slightly different...
    RangeFilter rangeFilt = new RangeFilter(fieldName,
            lowerVal!=null?lowerVal:"",
            upperVal, lowerVal==""?false:includeLower, upperVal==null?false:includeUpper);
    Query q = new ConstantScoreQuery(rangeFilt);
    q.setBoost(getBoost());
    return q;
  
public java.lang.StringtoString(java.lang.String field)
Prints a user-readable version of this query.

        StringBuffer buffer = new StringBuffer();
        if (!getField().equals(field))
        {
            buffer.append(getField());
            buffer.append(":");
        }
        buffer.append(includeLower ? '[" : '{");
        buffer.append(lowerVal != null ? lowerVal : "*");
        buffer.append(" TO ");
        buffer.append(upperVal != null ? upperVal : "*");
        buffer.append(includeUpper ? ']" : '}");
        if (getBoost() != 1.0f)
        {
            buffer.append("^");
            buffer.append(Float.toString(getBoost()));
        }
        return buffer.toString();