FileDocCategorySizeDatePackage
NearSpansUnordered.javaAPI DocApache Lucene 2.1.07264Wed Feb 14 10:46:38 GMT 2007org.apache.lucene.search.spans

NearSpansUnordered

public class NearSpansUnordered extends Object implements Spans
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Fields Summary
private SpanNearQuery
query
private List
ordered
private int
slop
private SpansCell
first
private SpansCell
last
private int
totalLength
private CellQueue
queue
private SpansCell
max
private boolean
more
private boolean
firstTime
Constructors Summary
public NearSpansUnordered(SpanNearQuery query, IndexReader reader)

    this.query = query;
    this.slop = query.getSlop();

    SpanQuery[] clauses = query.getClauses();
    queue = new CellQueue(clauses.length);
    for (int i = 0; i < clauses.length; i++) {
      SpansCell cell =
        new SpansCell(clauses[i].getSpans(reader), i);
      ordered.add(cell);
    }
  
Methods Summary
private voidaddToList(org.apache.lucene.search.spans.NearSpansUnordered$SpansCell cell)

    if (last != null) {			  // add next to end of list
      last.next = cell;
    } else
      first = cell;
    last = cell;
    cell.next = null;
  
private booleanatMatch()

    return (min().doc() == max.doc())
        && ((max.end() - min().start() - totalLength) <= slop);
  
public intdoc()

 return min().doc(); 
public intend()

 return max.end(); 
private voidfirstToLast()

    last.next = first;			  // move first to end of list
    last = first;
    first = first.next;
    last.next = null;
  
private voidinitList(boolean next)

    for (int i = 0; more && i < ordered.size(); i++) {
      SpansCell cell = (SpansCell)ordered.get(i);
      if (next)
        more = cell.next();                       // move to first entry
      if (more) {
        addToList(cell);                          // add to list
      }
    }
  
private voidlistToQueue()

    queue.clear(); // rebuild queue
    for (SpansCell cell = first; cell != null; cell = cell.next) {
      queue.put(cell);                      // add to queue from list
    }
  
private org.apache.lucene.search.spans.NearSpansUnordered$SpansCellmin()

 return (SpansCell)queue.top(); 
public booleannext()

    if (firstTime) {
      initList(true);
      listToQueue(); // initialize queue
      firstTime = false;
    } else if (more) {
      if (min().next()) { // trigger further scanning
        queue.adjustTop(); // maintain queue
      } else {
        more = false;
      }
    }

    while (more) {

      boolean queueStale = false;

      if (min().doc() != max.doc()) {             // maintain list
        queueToList();
        queueStale = true;
      }

      // skip to doc w/ all clauses

      while (more && first.doc() < last.doc()) {
        more = first.skipTo(last.doc());          // skip first upto last
        firstToLast();                            // and move it to the end
        queueStale = true;
      }

      if (!more) return false;

      // found doc w/ all clauses

      if (queueStale) {                           // maintain the queue
        listToQueue();
        queueStale = false;
      }

      if (atMatch()) {
        return true;
      }
      
      more = min().next();
      if (more) {
        queue.adjustTop();                      // maintain queue
      }
    }
    return false;                                 // no more matches
  
private voidqueueToList()

    last = first = null;
    while (queue.top() != null) {
      addToList((SpansCell)queue.pop());
    }
  
public booleanskipTo(int target)

    if (firstTime) {                              // initialize
      initList(false);
      for (SpansCell cell = first; more && cell!=null; cell=cell.next) {
        more = cell.skipTo(target);               // skip all
      }
      if (more) {
        listToQueue();
      }
      firstTime = false;
    } else {                                      // normal case
      while (more && min().doc() < target) {      // skip as needed
        if (min().skipTo(target)) {
          queue.adjustTop();
        } else {
          more = false;
        }
      }
    }
    return more && (atMatch() ||  next());
  
public intstart()

 return min().start(); 
public java.lang.StringtoString()

    return getClass().getName() + "("+query.toString()+")@"+
      (firstTime?"START":(more?(doc()+":"+start()+"-"+end()):"END"));