lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1578523 - in /lucene/dev/branches/lucene_solr_4_7: ./ lucene/ lucene/CHANGES.txt lucene/queries/ lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java
Date Mon, 17 Mar 2014 19:18:13 GMT
Author: rmuir
Date: Mon Mar 17 19:18:12 2014
New Revision: 1578523

URL: http://svn.apache.org/r1578523
Log:
LUCENE-5502: Fix TermsFilter.equals

Modified:
    lucene/dev/branches/lucene_solr_4_7/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/queries/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java
    lucene/dev/branches/lucene_solr_4_7/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/CHANGES.txt?rev=1578523&r1=1578522&r2=1578523&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/CHANGES.txt Mon Mar 17 19:18:12 2014
@@ -27,6 +27,9 @@ Bug Fixes
 * LUCENE-5466: query is always null in countDocsWithClass() of SimpleNaiveBayesClassifier.
   (Koji Sekiguchi)
 
+* LUCENE-5502: Fixed TermsFilter.equals that could return true for different
+  filters. (Igor Motov via Adrien Grand)
+
 * LUCENE-5532: AutomatonQuery.hashCode was not thread-safe. (Robert Muir)
 
 Build

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java?rev=1578523&r1=1578522&r2=1578523&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java
(original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java
Mon Mar 17 19:18:12 2014
@@ -222,24 +222,14 @@ public final class TermsFilter extends F
     }
     
     TermsFilter test = (TermsFilter) obj;
-    if (test.hashCode == hashCode && this.termsAndFields.length == test.termsAndFields.length)
{
-      // first check the fields before even comparing the bytes
-      for (int i = 0; i < termsAndFields.length; i++) {
-        TermsAndField current = termsAndFields[i];
-        if (!current.equals(test.termsAndFields[i])) {
-          return false;
-        }
-      }
-      // straight byte comparison since we sort they must be identical
-      int end = offsets[termsAndFields.length];
-      byte[] left = this.termsBytes;
-      byte[] right = test.termsBytes;
-      for(int i=0;i < end;i++) {
-        if (left[i] != right[i]) {
-          return false;
-        }
+    // first check the fields before even comparing the bytes
+    if (test.hashCode == hashCode && Arrays.equals(termsAndFields, test.termsAndFields))
{
+      int lastOffset = termsAndFields[termsAndFields.length - 1].end;
+      // compare offsets since we sort they must be identical
+      if (ArrayUtil.equals(offsets, 0, test.offsets, 0, lastOffset + 1)) {
+        // straight byte comparison since we sort they must be identical
+        return  ArrayUtil.equals(termsBytes, 0, test.termsBytes, 0, offsets[lastOffset]);
       }
-      return true;
     }
     return false;
   }

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java?rev=1578523&r1=1578522&r2=1578523&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java
(original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java
Mon Mar 17 19:18:12 2014
@@ -296,7 +296,15 @@ public class TermsFilterTest extends Luc
       }
     }
   }
-  
+
+  public void testSingleFieldEquals() {
+    // Two terms with the same hash code
+    assertEquals("AaAaBB".hashCode(), "BBBBBB".hashCode());
+    TermsFilter left = termsFilter(true, new Term("id", "AaAaAa"), new Term("id", "AaAaBB"));
+    TermsFilter right = termsFilter(true, new Term("id", "AaAaAa"), new Term("id", "BBBBBB"));
+    assertFalse(left.equals(right));
+  }
+
   public void testNoTerms() {
     List<Term> emptyTerms = Collections.emptyList();
     List<BytesRef> emptyBytesRef = Collections.emptyList();



Mime
View raw message