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
This commit is contained in:
Martijn van Groningen 2011-10-08 14:10:09 +00:00
parent 40426f3464
commit 9ccc145128
5 changed files with 34 additions and 7 deletions

View File

@ -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

View File

@ -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<Integer> counts = (NamedList<Integer>) values.get("counts");

View File

@ -32,11 +32,16 @@ public abstract class RangeFacet<B, G> {
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<B, G> {
return gap;
}
public Number getBefore() {
return before;
}
public Number getAfter() {
return after;
}
public static class Numeric extends RangeFacet<Number, Number> {
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<java.util.Date, String> {
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);
}
}

View File

@ -72,6 +72,8 @@
<str name="gap">+1YEAR</str>
<date name="start">2005-02-13T15:26:37Z</date>
<date name="end">2008-02-13T15:26:37Z</date>
<int name="before">90</int>
<int name="after">1</int>
</lst>
</lst>
</lst>

View File

@ -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