FileDocCategorySizeDatePackage
SpanNearQuery.javaAPI DocApache Lucene 1.4.33634Mon Feb 02 13:27:52 GMT 2004org.apache.lucene.search.spans

SpanNearQuery

public class SpanNearQuery extends SpanQuery
Matches spans which are near one another. One can specify slop, the maximum number of intervening unmatched positions, as well as whether matches are required to be in-order.

Fields Summary
private List
clauses
private int
slop
private boolean
inOrder
private String
field
Constructors Summary
public SpanNearQuery(SpanQuery[] clauses, int slop, boolean inOrder)
Construct a SpanNearQuery. Matches spans matching a span from each clause, with up to slop total unmatched positions between them. * When inOrder is true, the spans from each clause must be * ordered as in clauses.


    // copy clauses array into an ArrayList
    this.clauses = new ArrayList(clauses.length);
    for (int i = 0; i < clauses.length; i++) {
      SpanQuery clause = clauses[i];
      if (i == 0) {                               // check field
        field = clause.getField();
      } else if (!clause.getField().equals(field)) {
        throw new IllegalArgumentException("Clauses must have same field.");
      }
      this.clauses.add(clause);
    }

    this.slop = slop;
    this.inOrder = inOrder;
  
Methods Summary
public org.apache.lucene.search.spans.SpanQuery[]getClauses()
Return the clauses whose spans are matched.

    return (SpanQuery[])clauses.toArray(new SpanQuery[clauses.size()]);
  
public java.lang.StringgetField()

 return field; 
public intgetSlop()
Return the maximum number of intervening unmatched positions permitted.

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

    if (clauses.size() == 0)                      // optimize 0-clause case
      return new SpanOrQuery(getClauses()).getSpans(reader);

    if (clauses.size() == 1)                      // optimize 1-clause case
      return ((SpanQuery)clauses.get(0)).getSpans(reader);

    return new NearSpans(this, reader);
  
public java.util.CollectiongetTerms()

    Collection terms = new ArrayList();
    Iterator i = clauses.iterator();
    while (i.hasNext()) {
      SpanQuery clause = (SpanQuery)i.next();
      terms.addAll(clause.getTerms());
    }
    return terms;
  
public booleanisInOrder()
Return true if matches are required to be in-order.

 return inOrder; 
public java.lang.StringtoString(java.lang.String field)

    StringBuffer buffer = new StringBuffer();
    buffer.append("spanNear([");
    Iterator i = clauses.iterator();
    while (i.hasNext()) {
      SpanQuery clause = (SpanQuery)i.next();
      buffer.append(clause.toString(field));
      if (i.hasNext()) {
        buffer.append(", ");
      }
    }
    buffer.append("], ");
    buffer.append(slop);
    buffer.append(", ");
    buffer.append(inOrder);
    buffer.append(")");
    return buffer.toString();