From ce57e8a8f4274db9ad1a78f06d37a7c9e02b3fb8 Mon Sep 17 00:00:00 2001 From: Tomas Fernandez Lobbe Date: Mon, 24 Oct 2016 19:49:54 -0700 Subject: [PATCH] Fixed Interval Facet count issue in cases of open/close intervals on the same values --- solr/CHANGES.txt | 5 ++++- .../java/org/apache/solr/request/IntervalFacets.java | 12 +++++++++++- .../apache/solr/request/TestIntervalFaceting.java | 7 ++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 4355b80d553..475ba7f6853 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -208,6 +208,9 @@ Bug Fixes * SOLR-9518: Kerberos Delegation Tokens don't work without a chrooted ZK (Ishan Chattopadhyaya,via noble) +* SOLR-9687: Fixed Interval Facet count issue in cases of open/close intervals on the same values + (Andy Chillrud, Tomás Fernández Löbbe) + Optimizations ---------------------- @@ -3290,7 +3293,7 @@ Bug Fixes while accessing other collections. (Shai Erera) * SOLR-7412: Fixed range.facet.other parameter for distributed requests. - (Will Miller, Tomás Fernándes Löbbe) + (Will Miller, Tomás Fernández Löbbe) * SOLR-6087: SolrIndexSearcher makes no DelegatingCollector.finish() call when IndexSearcher throws an expected exception. (Christine Poerschke via shalin) diff --git a/solr/core/src/java/org/apache/solr/request/IntervalFacets.java b/solr/core/src/java/org/apache/solr/request/IntervalFacets.java index dfe0f77f3af..14bf700bee7 100644 --- a/solr/core/src/java/org/apache/solr/request/IntervalFacets.java +++ b/solr/core/src/java/org/apache/solr/request/IntervalFacets.java @@ -157,7 +157,17 @@ public class IntervalFacets implements Iterable { if (o2.start == null) { return 1; } - return o1.start.compareTo(o2.start); + int startComparison = o1.start.compareTo(o2.start); + if (startComparison == 0) { + if (o1.startOpen != o2.startOpen) { + if (!o1.startOpen) { + return -1; + } else { + return 1; + } + } + } + return startComparison; } }); return sortedIntervals; diff --git a/solr/core/src/test/org/apache/solr/request/TestIntervalFaceting.java b/solr/core/src/test/org/apache/solr/request/TestIntervalFaceting.java index 68eac486495..5a4510f9193 100644 --- a/solr/core/src/test/org/apache/solr/request/TestIntervalFaceting.java +++ b/solr/core/src/test/org/apache/solr/request/TestIntervalFaceting.java @@ -943,6 +943,9 @@ public class TestIntervalFaceting extends SolrTestCaseJ4 { assertIntervalQuery(field, "(0,2]", "2"); assertIntervalQuery(field, "[*,5]", "6"); assertIntervalQuery(field, "[*,3)", "3", "[2,5)", "3", "[6,8)", "2", "[3,*]", "7", "[10,10]", "1", "[10,10]", "1", "[10,10]", "1"); + assertIntervalQuery(field, "(5,*]", "4", "[5,5]", "1", "(*,5)", "5"); + assertIntervalQuery(field, "[5,5]", "1", "(*,5)", "5", "(5,*]", "4"); + assertIntervalQuery(field, "(5,*]", "4", "(*,5)", "5", "[5,5]", "1"); } @@ -955,7 +958,9 @@ public class TestIntervalFaceting extends SolrTestCaseJ4 { assertIntervalQuery(field, "[*,bird)", "2", "[bird,cat)", "1", "[cat,dog)", "2", "[dog,*]", "4"); assertIntervalQuery(field, "[*,*]", "9", "[*,dog)", "5", "[*,dog]", "8", "[dog,*]", "4"); assertIntervalQuery(field, field + ":dog", 3, "[*,*]", "3", "[*,dog)", "0", "[*,dog]", "3", "[dog,*]", "3", "[bird,cat]", "0"); - + assertIntervalQuery(field, "(*,dog)", "5", "[dog, dog]", "3", "(dog,*)", "1"); + assertIntervalQuery(field, "[dog, dog]", "3", "(dog,*)", "1", "(*,dog)", "5"); + assertIntervalQuery(field, "(dog,*)", "1", "(*,dog)", "5", "[dog, dog]", "3"); } /**