FileDocCategorySizeDatePackage
SpanFirstQuery.javaAPI DocApache Lucene 2.0.04016Fri May 26 09:54:16 BST 2006org.apache.lucene.search.spans

SpanFirstQuery

public class SpanFirstQuery extends SpanQuery
Matches spans near the beginning of a field.

Fields Summary
private SpanQuery
match
private int
end
Constructors Summary
public SpanFirstQuery(SpanQuery match, int end)
Construct a SpanFirstQuery matching spans in match whose end position is less than or equal to end.

    this.match = match;
    this.end = end;
  
Methods Summary
public booleanequals(java.lang.Object o)

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

    SpanFirstQuery other = (SpanFirstQuery)o;
    return this.end == other.end
         && this.match.equals(other.match)
         && this.getBoost() == other.getBoost();
  
public voidextractTerms(java.util.Set terms)

	    match.extractTerms(terms);
  
public intgetEnd()
Return the maximum end position permitted in a match.

 return end; 
public java.lang.StringgetField()

 return match.getField(); 
public org.apache.lucene.search.spans.SpanQuerygetMatch()
Return the SpanQuery whose matches are filtered.

 return match; 
public org.apache.lucene.search.spans.SpansgetSpans(org.apache.lucene.index.IndexReader reader)

    return new Spans() {
        private Spans spans = match.getSpans(reader);

        public boolean next() throws IOException {
          while (spans.next()) {                  // scan to next match
            if (end() <= end)
              return true;
          }
          return false;
        }

        public boolean skipTo(int target) throws IOException {
          if (!spans.skipTo(target))
            return false;

          if (spans.end() <= end)                 // there is a match
            return true;

          return next();                          // scan to next match
        }

        public int doc() { return spans.doc(); }
        public int start() { return spans.start(); }
        public int end() { return spans.end(); }

        public String toString() {
          return "spans(" + SpanFirstQuery.this.toString() + ")";
        }

      };
  
public java.util.CollectiongetTerms()
Returns a collection of all terms matched by this query.

deprecated
use extractTerms instead
see
#extractTerms(Set)

 return match.getTerms(); 
public inthashCode()

    int h = match.hashCode();
    h ^= (h << 8) | (h >>> 25);  // reversible
    h ^= Float.floatToRawIntBits(getBoost()) ^ end;
    return h;
  
public org.apache.lucene.search.Queryrewrite(org.apache.lucene.index.IndexReader reader)

    SpanFirstQuery clone = null;

    SpanQuery rewritten = (SpanQuery) match.rewrite(reader);
    if (rewritten != match) {
      clone = (SpanFirstQuery) this.clone();
      clone.match = rewritten;
    }

    if (clone != null) {
      return clone;                        // some clauses rewrote
    } else {
      return this;                         // no clauses rewrote
    }
  
public java.lang.StringtoString(java.lang.String field)

    StringBuffer buffer = new StringBuffer();
    buffer.append("spanFirst(");
    buffer.append(match.toString(field));
    buffer.append(", ");
    buffer.append(end);
    buffer.append(")");
    buffer.append(ToStringUtils.boost(getBoost()));
    return buffer.toString();