lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r806885 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java src/java/org/apache/lucene/search/spans/SpanNearQuery.java src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java
Date Sat, 22 Aug 2009 20:23:01 GMT
Author: markrmiller
Date: Sat Aug 22 20:23:00 2009
New Revision: 806885

URL: http://svn.apache.org/viewvc?rev=806885&view=rev
Log:
LUCENE-1838: BoostingNearQuery must implement clone/toString

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=806885&r1=806884&r2=806885&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Sat Aug 22 20:23:00 2009
@@ -692,7 +692,7 @@
     disable 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 payloads
     based on the maximum payload seen for a document.

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java?rev=806885&r1=806884&r2=806885&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java Sat
Aug 22 20:23:00 2009
@@ -29,6 +29,7 @@
 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 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 @@
     }
   }
   
-  //@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;
-  }
-
-
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java?rev=806885&r1=806884&r2=806885&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanNearQuery.java Sat Aug 22
20:23:00 2009
@@ -34,9 +34,9 @@
  * 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;

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java?rev=806885&r1=806884&r2=806885&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java
(original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java
Sat Aug 22 20:23:00 2009
@@ -121,6 +121,7 @@
 		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



Mime
View raw message