aboutsummaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2018-10-12 10:54:56 +0000
committerArne Juul <arnej@yahoo-inc.com>2018-10-12 10:54:59 +0000
commit31fb1ecef52aac96e91db4a5cb94ec0f2d153fa8 (patch)
tree7c49f6b07dcb4cc4ae44bb7470c6a19c64801ff8 /container-search
parent8b75677b527deffe2b4852418ab498c2bc3e3d95 (diff)
sort missing (null) field values
* since we no longer force fill empty fields, we must handle the case where some fields in some hits are missing, and sort in a predictable manner.
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/search/result/FieldComparator.java11
1 files changed, 6 insertions, 5 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/result/FieldComparator.java b/container-search/src/main/java/com/yahoo/search/result/FieldComparator.java
index 21650d531be..e64e0bc8f8d 100644
--- a/container-search/src/main/java/com/yahoo/search/result/FieldComparator.java
+++ b/container-search/src/main/java/com/yahoo/search/result/FieldComparator.java
@@ -57,11 +57,6 @@ public class FieldComparator extends ChainableComparator {
Object a = getField(first,fieldName);
Object b = getField(second,fieldName);
- // If either of the values are null, don't touch the ordering
- // This is to avoid problems if the sorting is called before the
- // result is filled.
- if ((a == null) || (b == null)) return 0;
-
int x = compareValues(a, b, fieldOrder.getSorter());
if (x != 0) {
if (fieldOrder.getSortOrder() == Sorting.Order.DESCENDING)
@@ -81,6 +76,12 @@ public class FieldComparator extends ChainableComparator {
@SuppressWarnings("rawtypes")
private int compareValues(Object first, Object second, Sorting.AttributeSorter s) {
+ if (first == null) {
+ if (second == null) return 0;
+ return -1;
+ } else if (second == null) {
+ return 1;
+ }
if (first.getClass().isInstance(second)
&& first instanceof Comparable) {
// We now know: