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

SpanTermQuery

public class SpanTermQuery extends SpanQuery
Matches spans containing a term.

Fields Summary
private Term
term
Constructors Summary
public SpanTermQuery(Term term)
Construct a SpanTermQuery matching the named term's spans.

 this.term = term; 
Methods Summary
public booleanequals(java.lang.Object o)
Returns true iff o is equal to this.

    if (!(o instanceof SpanTermQuery))
      return false;
    SpanTermQuery other = (SpanTermQuery)o;
    return (this.getBoost() == other.getBoost())
      && this.term.equals(other.term);
  
public voidextractTerms(java.util.Set terms)

	  terms.add(term);
  
public java.lang.StringgetField()

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

    return new Spans() {
        private TermPositions positions = reader.termPositions(term);

        private int doc = -1;
        private int freq;
        private int count;
        private int position;

        public boolean next() throws IOException {
          if (count == freq) {
            if (!positions.next()) {
              doc = Integer.MAX_VALUE;
              return false;
            }
            doc = positions.doc();
            freq = positions.freq();
            count = 0;
          }
          position = positions.nextPosition();
          count++;
          return true;
        }

        public boolean skipTo(int target) throws IOException {
          // are we already at the correct position?
          if (doc >= target) {
            return true;
          }

          if (!positions.skipTo(target)) {
            doc = Integer.MAX_VALUE;
            return false;
          }

          doc = positions.doc();
          freq = positions.freq();
          count = 0;

          position = positions.nextPosition();
          count++;

          return true;
        }

        public int doc() { return doc; }
        public int start() { return position; }
        public int end() { return position + 1; }

        public String toString() {
          return "spans(" + SpanTermQuery.this.toString() + ")@"+
            (doc==-1?"START":(doc==Integer.MAX_VALUE)?"END":doc+"-"+position);
        }

      };
  
public org.apache.lucene.index.TermgetTerm()
Return the term whose spans are matched.

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

deprecated
use extractTerms instead
see
#extractTerms(Set)

    Collection terms = new ArrayList();
    terms.add(term);
    return terms;
  
public inthashCode()
Returns a hash code value for this object.

    return Float.floatToIntBits(getBoost()) ^ term.hashCode() ^ 0xD23FE494;
  
public java.lang.StringtoString(java.lang.String field)

    StringBuffer buffer = new StringBuffer();
    if (term.field().equals(field))
      buffer.append(term.text());
    else
      buffer.append(term.toString());
    buffer.append(ToStringUtils.boost(getBoost()));
    return buffer.toString();