Apache Lucene open-source search software
LUCENE-1838: BoostingNearQuery must implement clone/toString
Mark Robert Miller136f054a0571
diff --git a/CHANGES.txt b/CHANGES.txtindex 7867c072585..416c6792727 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -692,7 +692,7 @@ New featuresdisable loading them with a new constructor switch. (Mark Miller)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 payloadsbased on the maximum payload seen for a document.diff --git a/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java b/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.javaindex faa05a25a16..00a7da7efb2 100644--- a/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java+++ b/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java@@ -29,6 +29,7 @@ import org.apache.lucene.search.spans.SpanQuery;import org.apache.lucene.search.spans.SpanScorer;import org.apache.lucene.search.spans.SpanWeight;import org.apache.lucene.search.spans.Spans;+import org.apache.lucene.util.ToStringUtils;import java.io.IOException;import java.util.Collection;@@ -65,6 +66,70 @@ public class BoostingNearQuery extends SpanNearQuery implements PayloadQuery {public Weight createWeight(Searcher searcher) throws IOException {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 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;- }--}diff --git a/src/java/org/apache/lucene/search/spans/SpanNearQuery.java b/src/java/org/apache/lucene/search/spans/SpanNearQuery.javaindex 84830611cff..f8d0d78c7f6 100644--- a/src/java/org/apache/lucene/search/spans/SpanNearQuery.java+++ b/src/java/org/apache/lucene/search/spans/SpanNearQuery.java@@ -34,9 +34,9 @@ import org.apache.lucene.util.ToStringUtils;* maximum number of intervening unmatched positions, as well as whether* matches are required to be in-order. */public class SpanNearQuery extends SpanQuery implements Cloneable {- private List clauses;- private int slop;- private boolean inOrder;+ protected List clauses;+ protected int slop;+ protected boolean inOrder;protected String field;private boolean collectPayloads;diff --git a/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java b/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.javaindex c031eb97833..f46aca64fda 100644--- a/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java+++ b/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java@@ -121,6 +121,7 @@ public class TestBoostingNearQuery extends LuceneTestCase {TopDocs hits;query = newPhraseQuery("field", "twenty two", true);+ QueryUtils.check(query);// all 10 hits should have score = 3 because adjacent terms have payloads of 2,4// and all the similarity factors are set to 1