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.String | getField() return field;
|
public org.apache.lucene.search.spans.Spans | getSpans(org.apache.lucene.index.IndexReader reader)
if (clauses.size() == 1) // optimize 1-clause case
return ((SpanQuery)clauses.get(0)).getSpans(reader);
return new Spans() {
private List all = new ArrayList(clauses.size());
private SpanQueue queue = new SpanQueue(clauses.size());
{
Iterator i = clauses.iterator();
while (i.hasNext()) { // initialize all
all.add(((SpanQuery)i.next()).getSpans(reader));
}
}
private boolean firstTime = true;
public boolean next() throws IOException {
if (firstTime) { // first time -- initialize
for (int i = 0; i < all.size(); i++) {
Spans spans = (Spans)all.get(i);
if (spans.next()) { // move to first entry
queue.put(spans); // build queue
} else {
all.remove(i--);
}
}
firstTime = false;
return queue.size() != 0;
}
if (queue.size() == 0) { // all done
return false;
}
if (top().next()) { // move to next
queue.adjustTop();
return true;
}
all.remove(queue.pop()); // exhausted a clause
return queue.size() != 0;
}
private Spans top() { return (Spans)queue.top(); }
public boolean skipTo(int target) throws IOException {
if (firstTime) {
for (int i = 0; i < all.size(); i++) {
Spans spans = (Spans)all.get(i);
if (spans.skipTo(target)) { // skip each spans in all
queue.put(spans); // build queue
} else {
all.remove(i--);
}
}
firstTime = false;
} else {
while (queue.size() != 0 && top().doc() < target) {
if (top().skipTo(target)) {
queue.adjustTop();
} else {
all.remove(queue.pop());
}
}
}
return queue.size() != 0;
}
public int doc() { return top().doc(); }
public int start() { return top().start(); }
public int end() { return top().end(); }
public String toString() {
return "spans("+SpanOrQuery.this+")@"+
(firstTime?"START"
:(queue.size()>0?(doc()+":"+start()+"-"+end()):"END"));
}
};
|
public java.util.Collection | getTerms()
Collection terms = new ArrayList();
Iterator i = clauses.iterator();
while (i.hasNext()) {
SpanQuery clause = (SpanQuery)i.next();
terms.addAll(clause.getTerms());
}
return terms;
|
public java.lang.String | toString(java.lang.String field)
StringBuffer buffer = new StringBuffer();
buffer.append("spanOr([");
Iterator i = clauses.iterator();
while (i.hasNext()) {
SpanQuery clause = (SpanQuery)i.next();
buffer.append(clause.toString(field));
if (i.hasNext()) {
buffer.append(", ");
}
}
buffer.append("])");
return buffer.toString();
|