lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject [1/6] lucene-solr:master: LUCENE-7808: Fix PayloadScoreQuery and SpanPayloadCheckQuery .equals and .hashCode methods.
Date Thu, 27 Apr 2017 19:45:51 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 0f3bcf347 -> 64caf176b


LUCENE-7808: Fix PayloadScoreQuery and SpanPayloadCheckQuery .equals and .hashCode methods.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/28aeeadb
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/28aeeadb
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/28aeeadb

Branch: refs/heads/master
Commit: 28aeeadb5f5d3ba74823da00250398b0a80a6ec1
Parents: 90b3ef1
Author: Erik Hatcher <ehatcher@apache.org>
Authored: Wed Apr 26 20:05:32 2017 -0400
Committer: Erik Hatcher <ehatcher@apache.org>
Committed: Wed Apr 26 20:05:32 2017 -0400

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  3 +++
 .../queries/payloads/PayloadScoreQuery.java     |  9 +++----
 .../queries/payloads/SpanPayloadCheckQuery.java | 16 +++++++++++--
 .../queries/payloads/TestPayloadCheckQuery.java | 22 ++++++++++++++++-
 .../queries/payloads/TestPayloadScoreQuery.java | 25 ++++++++++++++++++--
 5 files changed, 66 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28aeeadb/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f9cca9f..83ce747 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -100,6 +100,9 @@ Bug Fixes
 * LUCENE-7797: The static FSDirectory.listAll(Path) method was always
   returning an empty array.  (Atkins Chang via Mike McCandless)
 
+* LUCENE-7808: Fix PayloadScoreQuery and SpanPayloadCheckQuery
+  .equals and .hashCode methods.  (Erik Hatcher)
+
 Improvements
 
 * LUCENE-7782: OfflineSorter now passes the total number of items it

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28aeeadb/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java
b/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java
index 5669406..0cddd00 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java
@@ -82,7 +82,7 @@ public class PayloadScoreQuery extends SpanQuery {
 
   @Override
   public String toString(String field) {
-    return "PayloadSpanQuery[" + wrappedQuery.toString(field) + "; " + function.toString()
+ "]";
+    return "PayloadScoreQuery[" + wrappedQuery.toString(field) + "; " + function.getClass().getSimpleName()
+ "; " + includeSpanScore + "]";
   }
 
   @Override
@@ -101,7 +101,7 @@ public class PayloadScoreQuery extends SpanQuery {
   
   private boolean equalsTo(PayloadScoreQuery other) {
     return wrappedQuery.equals(other.wrappedQuery) && 
-           function.equals(other.function);
+           function.equals(other.function) && (includeSpanScore == other.includeSpanScore);
   }
 
   @Override
@@ -109,6 +109,7 @@ public class PayloadScoreQuery extends SpanQuery {
     int result = classHash();
     result = 31 * result + Objects.hashCode(wrappedQuery);
     result = 31 * result + Objects.hashCode(function);
+    result = 31 * result + Objects.hashCode(includeSpanScore);
     return result;
   }
 
@@ -132,7 +133,7 @@ public class PayloadScoreQuery extends SpanQuery {
     }
 
     @Override
-    public PayloadSpanScorer scorer(LeafReaderContext context) throws IOException {
+    public SpanScorer scorer(LeafReaderContext context) throws IOException {
       Spans spans = getSpans(context, Postings.PAYLOADS);
       if (spans == null)
         return null;
@@ -148,7 +149,7 @@ public class PayloadScoreQuery extends SpanQuery {
 
     @Override
     public Explanation explain(LeafReaderContext context, int doc) throws IOException {
-      PayloadSpanScorer scorer = scorer(context);
+      PayloadSpanScorer scorer = (PayloadSpanScorer)scorer(context);
       if (scorer == null || scorer.iterator().advance(doc) != doc)
         return Explanation.noMatch("No match");
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28aeeadb/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java
b/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java
index 57ba678..e33eb18 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java
@@ -18,14 +18,17 @@ package org.apache.lucene.queries.payloads;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.PostingsEnum;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.search.spans.FilterSpans;
 import org.apache.lucene.search.spans.FilterSpans.AcceptStatus;
@@ -64,6 +67,11 @@ public class SpanPayloadCheckQuery extends SpanQuery {
     return new SpanPayloadCheckWeight(searcher, needsScores ? getTermContexts(matchWeight)
: null, matchWeight, boost);
   }
 
+  @Override
+  public Query rewrite(IndexReader reader) throws IOException {
+    return super.rewrite(reader);
+  }
+
   /**
    * Weight that pulls its Spans using a PayloadSpanCollector
    */
@@ -175,11 +183,15 @@ public class SpanPayloadCheckQuery extends SpanQuery {
   @Override
   public boolean equals(Object other) {
     return sameClassAs(other) &&
-           payloadToMatch.equals(((SpanPayloadCheckQuery) other).payloadToMatch);
+           payloadToMatch.equals(((SpanPayloadCheckQuery) other).payloadToMatch) &&
+           match.equals(((SpanPayloadCheckQuery) other).match);
   }
 
   @Override
   public int hashCode() {
-    return classHash() ^ payloadToMatch.hashCode();
+    int result = classHash();
+    result = 31 * result + Objects.hashCode(match);
+    result = 31 * result + Objects.hashCode(payloadToMatch);
+    return result;
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28aeeadb/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadCheckQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadCheckQuery.java
b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadCheckQuery.java
index 7067ef2..ffe2cb8 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadCheckQuery.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadCheckQuery.java
@@ -188,4 +188,24 @@ public class TestPayloadCheckQuery extends LuceneTestCase {
     checkHits(query, new int[]{1103, 1203,1303,1403,1503,1603,1703,1803,1903});
 
   }
-}
+
+  public void testEquality() {
+    SpanQuery sq1 = new SpanTermQuery(new Term("field", "one"));
+    SpanQuery sq2 = new SpanTermQuery(new Term("field", "two"));
+    BytesRef payload1 = new BytesRef("pay1");
+    BytesRef payload2 = new BytesRef("pay2");
+    SpanQuery query1 = new SpanPayloadCheckQuery(sq1, Collections.singletonList(payload1));
+    SpanQuery query2 = new SpanPayloadCheckQuery(sq2, Collections.singletonList(payload1));
+    SpanQuery query3 = new SpanPayloadCheckQuery(sq1, Collections.singletonList(payload2));
+    SpanQuery query4 = new SpanPayloadCheckQuery(sq2, Collections.singletonList(payload2));
+    SpanQuery query5 = new SpanPayloadCheckQuery(sq1, Collections.singletonList(payload1));
+
+    assertEquals(query1, query5);
+    assertFalse(query1.equals(query2));
+    assertFalse(query1.equals(query3));
+    assertFalse(query1.equals(query4));
+    assertFalse(query2.equals(query3));
+    assertFalse(query2.equals(query4));
+    assertFalse(query3.equals(query4));
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/28aeeadb/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadScoreQuery.java
b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadScoreQuery.java
index 2afec44..fa38776 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadScoreQuery.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadScoreQuery.java
@@ -172,10 +172,31 @@ public class TestPayloadScoreQuery extends LuceneTestCase {
 
   }
 
+  @Test
+  public void testEquality() {
+    SpanQuery sq1 = new SpanTermQuery(new Term("field", "one"));
+    SpanQuery sq2 = new SpanTermQuery(new Term("field", "two"));
+    PayloadFunction minFunc = new MinPayloadFunction();
+    PayloadFunction maxFunc = new MaxPayloadFunction();
+    PayloadScoreQuery query1 = new PayloadScoreQuery(sq1, minFunc, true);
+    PayloadScoreQuery query2 = new PayloadScoreQuery(sq2, minFunc, true);
+    PayloadScoreQuery query3 = new PayloadScoreQuery(sq2, maxFunc, true);
+    PayloadScoreQuery query4 = new PayloadScoreQuery(sq2, maxFunc, false);
+    PayloadScoreQuery query5 = new PayloadScoreQuery(sq1, minFunc);
+
+    assertEquals(query1, query5);
+    assertFalse(query1.equals(query2));
+    assertFalse(query1.equals(query3));
+    assertFalse(query1.equals(query4));
+    assertFalse(query2.equals(query3));
+    assertFalse(query2.equals(query4));
+    assertFalse(query3.equals(query4));
+  }
+
   private static IndexSearcher searcher;
   private static IndexReader reader;
   private static Directory directory;
-  private static BoostingSimilarity similarity = new BoostingSimilarity();
+  private static JustScorePayloadSimilarity similarity = new JustScorePayloadSimilarity();
   private static byte[] payload2 = new byte[]{2};
   private static byte[] payload4 = new byte[]{4};
 
@@ -260,7 +281,7 @@ public class TestPayloadScoreQuery extends LuceneTestCase {
 
   }
 
-  static class BoostingSimilarity extends MultiplyingSimilarity {
+  static class JustScorePayloadSimilarity extends MultiplyingSimilarity {
 
     //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     //Make everything else 1 so we see the effect of the payload


Mime
View raw message