Methods Summary |
---|
public boolean | equals(java.lang.Object o)
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final SpanOrQuery that = (SpanOrQuery) o;
if (!clauses.equals(that.clauses)) return false;
if (!field.equals(that.field)) return false;
return getBoost() == that.getBoost();
|
public void | extractTerms(java.util.Set terms)
Iterator i = clauses.iterator();
while (i.hasNext()) {
SpanQuery clause = (SpanQuery)i.next();
clause.extractTerms(terms);
}
|
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()Returns a collection of all terms matched by this query.
Collection terms = new ArrayList();
Iterator i = clauses.iterator();
while (i.hasNext()) {
SpanQuery clause = (SpanQuery)i.next();
terms.addAll(clause.getTerms());
}
return terms;
|
public int | hashCode()
int h = clauses.hashCode();
h ^= (h << 10) | (h >>> 23);
h ^= Float.floatToRawIntBits(getBoost());
return h;
|
public org.apache.lucene.search.Query | rewrite(org.apache.lucene.index.IndexReader reader)
SpanOrQuery clone = null;
for (int i = 0 ; i < clauses.size(); i++) {
SpanQuery c = (SpanQuery)clauses.get(i);
SpanQuery query = (SpanQuery) c.rewrite(reader);
if (query != c) { // clause rewrote: must clone
if (clone == null)
clone = (SpanOrQuery) this.clone();
clone.clauses.set(i,query);
}
}
if (clone != null) {
return clone; // some clauses rewrote
} else {
return this; // no clauses rewrote
}
|
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("])");
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
|