You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by nk...@apache.org on 2016/02/08 23:35:57 UTC
[22/50] [abbrv] lucene-solr git commit: LUCENE-6946: SortField.equals
now takes the missing value into account.
LUCENE-6946: SortField.equals now takes the missing value into account.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene_solr_5_4@1724035 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/f0661970
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/f0661970
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/f0661970
Branch: refs/heads/branch_5_4
Commit: f06619702f7f72bc8a773d37104c1976c1fdbd96
Parents: 3edd73f
Author: Adrien Grand <jp...@apache.org>
Authored: Mon Jan 11 14:24:47 2016 +0000
Committer: Adrien Grand <jp...@apache.org>
Committed: Mon Jan 11 14:24:47 2016 +0000
----------------------------------------------------------------------
lucene/CHANGES.txt | 7 ++++
.../org/apache/lucene/search/SortField.java | 17 ++++-----
.../org/apache/lucene/util/StringHelper.java | 8 -----
.../test/org/apache/lucene/search/TestSort.java | 36 +++++++++++++++++++-
.../apache/lucene/util/TestStringHelper.java | 7 ----
5 files changed, 49 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f0661970/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 24f5e2e..84393ab 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -4,6 +4,13 @@ For more information on past and future Lucene versions, please see:
http://s.apache.org/luceneversions
+======================= Lucene 5.4.1 =======================
+
+Bug Fixes
+
+* LUCENE-6946: SortField.equals now takes the missingValue parameter into
+ account. (Adrien Grand)
+
======================= Lucene 5.4.0 =======================
New Features
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f0661970/lucene/core/src/java/org/apache/lucene/search/SortField.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/SortField.java b/lucene/core/src/java/org/apache/lucene/search/SortField.java
index daac17c..816c05c 100644
--- a/lucene/core/src/java/org/apache/lucene/search/SortField.java
+++ b/lucene/core/src/java/org/apache/lucene/search/SortField.java
@@ -19,9 +19,9 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.Comparator;
+import java.util.Objects;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.StringHelper;
/**
* Stores information about how to sort documents by terms in an individual
@@ -281,23 +281,20 @@ public class SortField {
if (!(o instanceof SortField)) return false;
final SortField other = (SortField)o;
return (
- StringHelper.equals(other.field, this.field)
+ Objects.equals(other.field, this.field)
&& other.type == this.type
&& other.reverse == this.reverse
- && (other.comparatorSource == null ? this.comparatorSource == null : other.comparatorSource.equals(this.comparatorSource))
+ && Objects.equals(this.comparatorSource, other.comparatorSource)
+ && Objects.equals(this.missingValue, other.missingValue)
);
}
- /** Returns true if <code>o</code> is equal to this. If a
+ /** Returns a hash code for this {@link SortField} instance. If a
* {@link FieldComparatorSource} was provided, it must properly
- * implement hashCode (unless a singleton is always
- * used). */
+ * implement hashCode (unless a singleton is always used). */
@Override
public int hashCode() {
- int hash = type.hashCode() ^ 0x346565dd + Boolean.valueOf(reverse).hashCode() ^ 0xaf5998bb;
- if (field != null) hash += field.hashCode()^0xff5685dd;
- if (comparatorSource != null) hash += comparatorSource.hashCode();
- return hash;
+ return Objects.hash(field, type, reverse, comparatorSource, missingValue);
}
private Comparator<BytesRef> bytesComparator = BytesRef.getUTF8SortedAsUnicodeComparator();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f0661970/lucene/core/src/java/org/apache/lucene/util/StringHelper.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/StringHelper.java b/lucene/core/src/java/org/apache/lucene/util/StringHelper.java
index f38321f..fdbc3a9 100644
--- a/lucene/core/src/java/org/apache/lucene/util/StringHelper.java
+++ b/lucene/core/src/java/org/apache/lucene/util/StringHelper.java
@@ -71,14 +71,6 @@ public abstract class StringHelper {
private StringHelper() {
}
- public static boolean equals(String s1, String s2) {
- if (s1 == null) {
- return s2 == null;
- } else {
- return s1.equals(s2);
- }
- }
-
/**
* Returns <code>true</code> iff the ref starts with the given prefix.
* Otherwise <code>false</code>.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f0661970/lucene/core/src/test/org/apache/lucene/search/TestSort.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSort.java b/lucene/core/src/test/org/apache/lucene/search/TestSort.java
index 3fb598c..d6311ad 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSort.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSort.java
@@ -48,7 +48,41 @@ import org.apache.lucene.util.LuceneTestCase;
* \./
*/
public class TestSort extends LuceneTestCase {
-
+
+ private void assertEquals(Sort a, Sort b) {
+ LuceneTestCase.assertEquals(a, b);
+ LuceneTestCase.assertEquals(b, a);
+ LuceneTestCase.assertEquals(a.hashCode(), b.hashCode());
+ }
+
+ private void assertDifferent(Sort a, Sort b) {
+ assertFalse(a.equals(b));
+ assertFalse(b.equals(a));
+ assertFalse(a.hashCode() == b.hashCode());
+ }
+
+ public void testEquals() {
+ SortField sortField1 = new SortField("foo", SortField.Type.STRING);
+ SortField sortField2 = new SortField("foo", SortField.Type.STRING);
+ assertEquals(new Sort(sortField1), new Sort(sortField2));
+
+ sortField2 = new SortField("bar", SortField.Type.STRING);
+ assertDifferent(new Sort(sortField1), new Sort(sortField2));
+
+ sortField2 = new SortField("foo", SortField.Type.LONG);
+ assertDifferent(new Sort(sortField1), new Sort(sortField2));
+
+ sortField2 = new SortField("foo", SortField.Type.STRING);
+ sortField2.setMissingValue(SortField.STRING_FIRST);
+ assertDifferent(new Sort(sortField1), new Sort(sortField2));
+
+ sortField2 = new SortField("foo", SortField.Type.STRING, false);
+ assertEquals(new Sort(sortField1), new Sort(sortField2));
+
+ sortField2 = new SortField("foo", SortField.Type.STRING, true);
+ assertDifferent(new Sort(sortField1), new Sort(sortField2));
+ }
+
/** Tests sorting on type string */
public void testString() throws IOException {
Directory dir = newDirectory();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f0661970/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java b/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
index 20bf2a4..be425e0 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
@@ -24,13 +24,6 @@ public class TestStringHelper extends LuceneTestCase {
BytesRef right = new BytesRef("foozo");
assertEquals(3, StringHelper.bytesDifference(left, right));
}
-
- public void testEquals() {
- assertTrue(StringHelper.equals("foo", "foo"));
- assertFalse(StringHelper.equals("foo", null));
- assertFalse(StringHelper.equals(null, "foo"));
- assertTrue(StringHelper.equals(null, null));
- }
public void testStartsWith() {
BytesRef ref = new BytesRef("foobar");