org.apache.lucene.search.payloads
public class: PayloadNearQuery [javadoc |
source]
java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.spans.SpanQuery
org.apache.lucene.search.spans.SpanNearQuery
org.apache.lucene.search.payloads.PayloadNearQuery
All Implemented Interfaces:
Cloneable, Serializable
This class is very similar to
org.apache.lucene.search.spans.SpanNearQuery except that it factors
in the value of the payloads located at each of the positions where the
org.apache.lucene.search.spans.TermSpans occurs.
In order to take advantage of this, you must override
org.apache.lucene.search.Similarity#scorePayload
which returns 1 by default.
Payload scores are aggregated using a pluggable
PayloadFunction .
Also see:
- org.apache.lucene.search.Similarity#scorePayload
Field Summary |
---|
protected String | fieldName | |
protected PayloadFunction | function | |
Constructor: |
public PayloadNearQuery(SpanQuery[] clauses,
int slop,
boolean inOrder) {
this(clauses, slop, inOrder, new AveragePayloadFunction());
}
|
public PayloadNearQuery(SpanQuery[] clauses,
int slop,
boolean inOrder,
PayloadFunction function) {
super(clauses, slop, inOrder);
fieldName = clauses[0].getField(); // all clauses must have same field
this.function = function;
}
|
Methods from org.apache.lucene.search.spans.SpanNearQuery: |
---|
clone, equals, extractTerms, getClauses, getField, getSlop, getSpans, hashCode, isInOrder, rewrite, toString |
Methods from org.apache.lucene.search.Query: |
---|
clone, combine, createWeight, equals, extractTerms, getBoost, getSimilarity, hashCode, mergeBooleanQueries, rewrite, setBoost, toString, toString, weight |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.lucene.search.payloads.PayloadNearQuery Detail: |
public Object clone() {
int sz = clauses.size();
SpanQuery[] newClauses = new SpanQuery[sz];
for (int i = 0; i < sz; i++) {
newClauses[i] = (SpanQuery) clauses.get(i).clone();
}
PayloadNearQuery boostingNearQuery = new PayloadNearQuery(newClauses, slop,
inOrder);
boostingNearQuery.setBoost(getBoost());
return boostingNearQuery;
}
|
public Weight createWeight(Searcher searcher) throws IOException {
return new PayloadNearSpanWeight(this, searcher);
}
|
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
PayloadNearQuery other = (PayloadNearQuery) obj;
if (fieldName == null) {
if (other.fieldName != null)
return false;
} else if (!fieldName.equals(other.fieldName))
return false;
if (function == null) {
if (other.function != null)
return false;
} else if (!function.equals(other.function))
return false;
return true;
}
|
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((fieldName == null) ? 0 : fieldName.hashCode());
result = prime * result + ((function == null) ? 0 : function.hashCode());
return result;
}
|
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
buffer.append("payloadNear([");
Iterator< SpanQuery > i = clauses.iterator();
while (i.hasNext()) {
SpanQuery clause = i.next();
buffer.append(clause.toString(field));
if (i.hasNext()) {
buffer.append(", ");
}
}
buffer.append("], ");
buffer.append(slop);
buffer.append(", ");
buffer.append(inOrder);
buffer.append(")");
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
}
|