From 9ccc1451280d742f9f26343d48e0e0e11a2391fe Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Sat, 8 Oct 2011 14:10:09 +0000 Subject: [PATCH] SOLR-2818: Added before/after count response parsing support for range facets in SolrJ. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1180377 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 +++ .../client/solrj/response/QueryResponse.java | 12 ++++++++-- .../client/solrj/response/RangeFacet.java | 22 ++++++++++++++----- .../solrj/sampleDateFacetResponse.xml | 2 ++ .../solrj/response/QueryResponseTest.java | 2 ++ 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index a41f89cfcbf..1911cbdcf3e 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -357,6 +357,9 @@ New Features * SOLR-1979: New contrib "langid". Adds language identification capabilities as an Update Processor, using Tika's LanguageIdentifier (janhoy, Tommaso Teofili, gsingers) +* SOLR-2818: Added before/after count response parsing support for range facets in + SolrJ. (Bernhard Frauendienst via Martijn van Groningen) + Bug Fixes ---------------------- * SOLR-2748: The CommitTracker used for commitWith or autoCommit by maxTime diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java index 6d52482f1d2..4999bb61ada 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java @@ -311,12 +311,20 @@ public class QueryResponse extends SolrResponseBase Number gap = (Number) rawGap; Number start = (Number) values.get("start"); Number end = (Number) values.get("end"); - rangeFacet = new RangeFacet.Numeric(facet.getKey(), start, end, gap); + + Number before = (Number) values.get("before"); + Number after = (Number) values.get("after"); + + rangeFacet = new RangeFacet.Numeric(facet.getKey(), start, end, gap, before, after); } else { String gap = (String) rawGap; Date start = (Date) values.get("start"); Date end = (Date) values.get("end"); - rangeFacet = new RangeFacet.Date(facet.getKey(), start, end, gap); + + Number before = (Number) values.get("before"); + Number after = (Number) values.get("after"); + + rangeFacet = new RangeFacet.Date(facet.getKey(), start, end, gap, before, after); } NamedList counts = (NamedList) values.get("counts"); diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/RangeFacet.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/RangeFacet.java index 5cd3c6566e4..d32b20c4ed4 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/RangeFacet.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/RangeFacet.java @@ -32,11 +32,16 @@ public abstract class RangeFacet { private final B end; private final G gap; - protected RangeFacet(String name, B start, B end, G gap) { + private final Number before; + private final Number after; + + protected RangeFacet(String name, B start, B end, G gap, Number before, Number after) { this.name = name; this.start = start; this.end = end; this.gap = gap; + this.before = before; + this.after = after; } public void addCount(String value, int count) { @@ -63,19 +68,26 @@ public abstract class RangeFacet { return gap; } + public Number getBefore() { + return before; + } + + public Number getAfter() { + return after; + } public static class Numeric extends RangeFacet { - public Numeric(String name, Number start, Number end, Number gap) { - super(name, start, end, gap); + public Numeric(String name, Number start, Number end, Number gap, Number before, Number after) { + super(name, start, end, gap, before, after); } } public static class Date extends RangeFacet { - public Date(String name, java.util.Date start, java.util.Date end, String gap) { - super(name, start, end, gap); + public Date(String name, java.util.Date start, java.util.Date end, String gap, Number before, Number after) { + super(name, start, end, gap, before, after); } } diff --git a/solr/solrj/src/test-files/solrj/sampleDateFacetResponse.xml b/solr/solrj/src/test-files/solrj/sampleDateFacetResponse.xml index e43c40ce576..a8f221f725e 100644 --- a/solr/solrj/src/test-files/solrj/sampleDateFacetResponse.xml +++ b/solr/solrj/src/test-files/solrj/sampleDateFacetResponse.xml @@ -72,6 +72,8 @@ +1YEAR 2005-02-13T15:26:37Z 2008-02-13T15:26:37Z + 90 + 1 diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java index d2cea4f24ef..253bb8f7bcf 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java @@ -112,6 +112,8 @@ public class QueryResponseTest extends LuceneTestCase { assertEquals(7, manufacturedateDt.getCounts().get(1).getCount()); assertEquals("2007-02-13T15:26:37Z", manufacturedateDt.getCounts().get(2).getValue()); assertEquals(0, manufacturedateDt.getCounts().get(2).getCount()); + assertEquals(90, manufacturedateDt.getBefore()); + assertEquals(1, manufacturedateDt.getAfter()); } @Test