Removes matches which overlap with another SpanQuery.
Method from org.apache.lucene.search.spans.SpanNotQuery Detail: |
public Object clone() {
SpanNotQuery spanNotQuery = new SpanNotQuery((SpanQuery)include.clone(),(SpanQuery) exclude.clone());
spanNotQuery.setBoost(getBoost());
return spanNotQuery;
}
|
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SpanNotQuery)) return false;
SpanNotQuery other = (SpanNotQuery)o;
return this.include.equals(other.include)
&& this.exclude.equals(other.exclude)
&& this.getBoost() == other.getBoost();
}
Returns true iff o is equal to this. |
public void extractTerms(Set<Term> terms) {
include.extractTerms(terms);
}
|
public SpanQuery getExclude() {
return exclude;
}
Return the SpanQuery whose matches must not overlap those returned. |
public String getField() {
return include.getField();
}
|
public SpanQuery getInclude() {
return include;
}
Return the SpanQuery whose matches are filtered. |
public Spans getSpans(IndexReader reader) throws IOException {
return new Spans() {
private Spans includeSpans = include.getSpans(reader);
private boolean moreInclude = true;
private Spans excludeSpans = exclude.getSpans(reader);
private boolean moreExclude = excludeSpans.next();
@Override
public boolean next() throws IOException {
if (moreInclude) // move to next include
moreInclude = includeSpans.next();
while (moreInclude && moreExclude) {
if (includeSpans.doc() > excludeSpans.doc()) // skip exclude
moreExclude = excludeSpans.skipTo(includeSpans.doc());
while (moreExclude // while exclude is before
&& includeSpans.doc() == excludeSpans.doc()
&& excludeSpans.end() < = includeSpans.start()) {
moreExclude = excludeSpans.next(); // increment exclude
}
if (!moreExclude // if no intersection
|| includeSpans.doc() != excludeSpans.doc()
|| includeSpans.end() < = excludeSpans.start())
break; // we found a match
moreInclude = includeSpans.next(); // intersected: keep scanning
}
return moreInclude;
}
@Override
public boolean skipTo(int target) throws IOException {
if (moreInclude) // skip include
moreInclude = includeSpans.skipTo(target);
if (!moreInclude)
return false;
if (moreExclude // skip exclude
&& includeSpans.doc() > excludeSpans.doc())
moreExclude = excludeSpans.skipTo(includeSpans.doc());
while (moreExclude // while exclude is before
&& includeSpans.doc() == excludeSpans.doc()
&& excludeSpans.end() < = includeSpans.start()) {
moreExclude = excludeSpans.next(); // increment exclude
}
if (!moreExclude // if no intersection
|| includeSpans.doc() != excludeSpans.doc()
|| includeSpans.end() < = excludeSpans.start())
return true; // we found a match
return next(); // scan to next match
}
@Override
public int doc() { return includeSpans.doc(); }
@Override
public int start() { return includeSpans.start(); }
@Override
public int end() { return includeSpans.end(); }
// TODO: Remove warning after API has been finalized
@Override
public Collection< byte[] > getPayload() throws IOException {
ArrayList< byte[] > result = null;
if (includeSpans.isPayloadAvailable()) {
result = new ArrayList< byte[] >(includeSpans.getPayload());
}
return result;
}
// TODO: Remove warning after API has been finalized
@Override
public boolean isPayloadAvailable() {
return includeSpans.isPayloadAvailable();
}
@Override
public String toString() {
return "spans(" + SpanNotQuery.this.toString() + ")";
}
};
}
|
public int hashCode() {
int h = include.hashCode();
h = (h< < 1) | (h > > > 31); // rotate left
h ^= exclude.hashCode();
h = (h< < 1) | (h > > > 31); // rotate left
h ^= Float.floatToRawIntBits(getBoost());
return h;
}
|
public Query rewrite(IndexReader reader) throws IOException {
SpanNotQuery clone = null;
SpanQuery rewrittenInclude = (SpanQuery) include.rewrite(reader);
if (rewrittenInclude != include) {
clone = (SpanNotQuery) this.clone();
clone.include = rewrittenInclude;
}
SpanQuery rewrittenExclude = (SpanQuery) exclude.rewrite(reader);
if (rewrittenExclude != exclude) {
if (clone == null) clone = (SpanNotQuery) this.clone();
clone.exclude = rewrittenExclude;
}
if (clone != null) {
return clone; // some clauses rewrote
} else {
return this; // no clauses rewrote
}
}
|
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
buffer.append("spanNot(");
buffer.append(include.toString(field));
buffer.append(", ");
buffer.append(exclude.toString(field));
buffer.append(")");
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
}
|