mirror of https://github.com/apache/lucene.git
LUCENE-1838: BoostingNearQuery must implement clone/toString
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@806885 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
426ffd809e
commit
136f054a05
|
@ -692,7 +692,7 @@ New features
|
||||||
disable loading them with a new constructor switch. (Mark Miller)
|
disable loading them with a new constructor switch. (Mark Miller)
|
||||||
|
|
||||||
33. LUCENE-1341: Added BoostingNearQuery to enable SpanNearQuery functionality
|
33. LUCENE-1341: Added BoostingNearQuery to enable SpanNearQuery functionality
|
||||||
with payloads (Peter Keegan, Grant Ingersoll)
|
with payloads (Peter Keegan, Grant Ingersoll, Mark Miller)
|
||||||
|
|
||||||
34. LUCENE-1790: Added BoostingFunctionTermQuery to enable scoring of payloads
|
34. LUCENE-1790: Added BoostingFunctionTermQuery to enable scoring of payloads
|
||||||
based on the maximum payload seen for a document.
|
based on the maximum payload seen for a document.
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.lucene.search.spans.SpanQuery;
|
||||||
import org.apache.lucene.search.spans.SpanScorer;
|
import org.apache.lucene.search.spans.SpanScorer;
|
||||||
import org.apache.lucene.search.spans.SpanWeight;
|
import org.apache.lucene.search.spans.SpanWeight;
|
||||||
import org.apache.lucene.search.spans.Spans;
|
import org.apache.lucene.search.spans.Spans;
|
||||||
|
import org.apache.lucene.util.ToStringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -65,6 +66,70 @@ public class BoostingNearQuery extends SpanNearQuery implements PayloadQuery {
|
||||||
public Weight createWeight(Searcher searcher) throws IOException {
|
public Weight createWeight(Searcher searcher) throws IOException {
|
||||||
return new BoostingSpanWeight(this, searcher);
|
return new BoostingSpanWeight(this, searcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object clone() {
|
||||||
|
int sz = clauses.size();
|
||||||
|
SpanQuery[] newClauses = new SpanQuery[sz];
|
||||||
|
|
||||||
|
for (int i = 0; i < sz; i++) {
|
||||||
|
SpanQuery clause = (SpanQuery) clauses.get(i);
|
||||||
|
newClauses[i] = (SpanQuery) clause.clone();
|
||||||
|
}
|
||||||
|
BoostingNearQuery boostingNearQuery = new BoostingNearQuery(newClauses, slop, inOrder);
|
||||||
|
boostingNearQuery.setBoost(getBoost());
|
||||||
|
return boostingNearQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(String field) {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("boostingNear([");
|
||||||
|
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(slop);
|
||||||
|
buffer.append(", ");
|
||||||
|
buffer.append(inOrder);
|
||||||
|
buffer.append(")");
|
||||||
|
buffer.append(ToStringUtils.boost(getBoost()));
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//@Override
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (!super.equals(obj))
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
BoostingNearQuery other = (BoostingNearQuery) 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 class BoostingSpanWeight extends SpanWeight {
|
public class BoostingSpanWeight extends SpanWeight {
|
||||||
public BoostingSpanWeight(SpanQuery query, Searcher searcher) throws IOException {
|
public BoostingSpanWeight(SpanQuery query, Searcher searcher) throws IOException {
|
||||||
|
@ -162,36 +227,4 @@ public class BoostingNearQuery extends SpanNearQuery implements PayloadQuery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Override
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (!super.equals(obj))
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
BoostingNearQuery other = (BoostingNearQuery) 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ import org.apache.lucene.util.ToStringUtils;
|
||||||
* maximum number of intervening unmatched positions, as well as whether
|
* maximum number of intervening unmatched positions, as well as whether
|
||||||
* matches are required to be in-order. */
|
* matches are required to be in-order. */
|
||||||
public class SpanNearQuery extends SpanQuery implements Cloneable {
|
public class SpanNearQuery extends SpanQuery implements Cloneable {
|
||||||
private List clauses;
|
protected List clauses;
|
||||||
private int slop;
|
protected int slop;
|
||||||
private boolean inOrder;
|
protected boolean inOrder;
|
||||||
|
|
||||||
protected String field;
|
protected String field;
|
||||||
private boolean collectPayloads;
|
private boolean collectPayloads;
|
||||||
|
|
|
@ -121,6 +121,7 @@ public class TestBoostingNearQuery extends LuceneTestCase {
|
||||||
TopDocs hits;
|
TopDocs hits;
|
||||||
|
|
||||||
query = newPhraseQuery("field", "twenty two", true);
|
query = newPhraseQuery("field", "twenty two", true);
|
||||||
|
QueryUtils.check(query);
|
||||||
|
|
||||||
// all 10 hits should have score = 3 because adjacent terms have payloads of 2,4
|
// all 10 hits should have score = 3 because adjacent terms have payloads of 2,4
|
||||||
// and all the similarity factors are set to 1
|
// and all the similarity factors are set to 1
|
||||||
|
|
Loading…
Reference in New Issue