mirror of https://github.com/apache/lucene.git
LUCENE-5502: Fix TermsFilter.equals.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1576223 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
54e1003047
commit
ffca357397
|
@ -156,6 +156,9 @@ Bug fixes
|
|||
* LUCENE-5507: Fix HunspellStemFilter loading of dictionaries with large amounts of aliases
|
||||
etc before the encoding declaration. (Robert Muir)
|
||||
|
||||
* LUCENE-5502: Fixed TermsFilter.equals that could return true for different
|
||||
filters. (Igor Motov via Adrien Grand)
|
||||
|
||||
Test Framework
|
||||
|
||||
* LUCENE-5449: Rename _TestUtil and _TestHelper to remove the leading _.
|
||||
|
|
|
@ -222,25 +222,15 @@ public final class TermsFilter extends Filter {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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
|
||||
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;
|
||||
return ArrayUtil.equals(termsBytes, 0, test.termsBytes, 0, offsets[lastOffset]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ import org.apache.lucene.util.BytesRef;
|
|||
import org.apache.lucene.util.FixedBitSet;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.TestUtil;
|
||||
import org.apache.lucene.util.TestUtil;
|
||||
|
||||
public class TermsFilterTest extends LuceneTestCase {
|
||||
|
||||
|
@ -298,6 +297,14 @@ public class TermsFilterTest extends LuceneTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue