SOLR-2538: Fix overflow but in range faceting on long/double when values bigger then max int/float are used

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1144014 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2011-07-07 20:18:55 +00:00
parent d10de2c435
commit fd337c605c
3 changed files with 89 additions and 3 deletions

View File

@ -302,6 +302,10 @@ Bug Fixes
* SOLR-2636: Fix explain functionality for negative queries. (Tom Hill via yonik) * SOLR-2636: Fix explain functionality for negative queries. (Tom Hill via yonik)
* SOLR-2538: Range Faceting on long/double fields could overflow if values
bigger then the max int/float were used.
(Erbi Hanka, hossman)
Other Changes Other Changes
---------------------- ----------------------

View File

@ -1317,7 +1317,7 @@ public class SimpleFacets {
} }
@Override @Override
public Double parseAndAddGap(Double value, String gap) { public Double parseAndAddGap(Double value, String gap) {
return new Double(value.floatValue() + Double.valueOf(gap).floatValue()); return new Double(value.doubleValue() + Double.valueOf(gap).doubleValue());
} }
} }
private static class IntegerRangeEndpointCalculator private static class IntegerRangeEndpointCalculator
@ -1343,7 +1343,7 @@ public class SimpleFacets {
} }
@Override @Override
public Long parseAndAddGap(Long value, String gap) { public Long parseAndAddGap(Long value, String gap) {
return new Long(value.intValue() + Long.valueOf(gap).intValue()); return new Long(value.longValue() + Long.valueOf(gap).longValue());
} }
} }
private static class DateRangeEndpointCalculator private static class DateRangeEndpointCalculator

View File

@ -892,7 +892,48 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {
public void testNumericRangeFacetsSortableDouble() { public void testNumericRangeFacetsSortableDouble() {
helpTestFractionalNumberRangeFacets("range_facet_sd"); helpTestFractionalNumberRangeFacets("range_facet_sd");
} }
private void helpTestFractionalNumberRangeFacets(final String fieldName) {
@Test
public void testNumericRangeFacetsOverflowTrieDouble() {
helpTestNumericRangeFacetsDoubleOverflow("range_facet_d");
}
@Test
public void testNumericRangeFacetsOverflowSortableDouble() {
helpTestNumericRangeFacetsDoubleOverflow("range_facet_sd");
}
private void helpTestNumericRangeFacetsDoubleOverflow(final String fieldName) {
final String f = fieldName;
final String pre = "//lst[@name='facet_ranges']/lst[@name='"+f+"']/lst[@name='counts']";
final String meta = pre + "/../";
String start = "0.0";
String gap = (new Double( (double)Float.MAX_VALUE )).toString();
String end = (new Double( ((double)Float.MAX_VALUE) * 3D )).toString();
String mid = (new Double( ((double)Float.MAX_VALUE) * 2D )).toString();
assertQ(f+": checking counts for lower",
req( "q", "id:[30 TO 60]"
,"rows", "0"
,"facet", "true"
,"facet.range", f
,"facet.range.start", start
,"facet.range.end", end
,"facet.range.gap", gap
,"facet.range.other", "all"
,"facet.range.include", "lower"
)
,"*[count("+pre+"/int)=3]"
,pre+"/int[@name='"+start+"'][.='6' ]"
,pre+"/int[@name='"+mid+"'][.='0' ]"
//
,meta+"/double[@name='end' ][.='"+end+"']"
,meta+"/int[@name='before' ][.='0']"
,meta+"/int[@name='after' ][.='0']"
,meta+"/int[@name='between'][.='6']"
);
}
private void helpTestFractionalNumberRangeFacets(final String fieldName) {
final String f = fieldName; final String f = fieldName;
final String pre = "//lst[@name='facet_ranges']/lst[@name='"+f+"']/lst[@name='counts']"; final String pre = "//lst[@name='facet_ranges']/lst[@name='"+f+"']/lst[@name='counts']";
@ -1112,6 +1153,47 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {
helpTestWholeNumberRangeFacets("range_facet_sl"); helpTestWholeNumberRangeFacets("range_facet_sl");
} }
@Test
public void testNumericRangeFacetsOverflowTrieLong() {
helpTestNumericRangeFacetsLongOverflow("range_facet_l");
}
@Test
public void testNumericRangeFacetsOverflowSortableLong() {
helpTestNumericRangeFacetsLongOverflow("range_facet_sl");
}
private void helpTestNumericRangeFacetsLongOverflow(final String fieldName) {
final String f = fieldName;
final String pre = "//lst[@name='facet_ranges']/lst[@name='"+f+"']/lst[@name='counts']";
final String meta = pre + "/../";
String start = "0";
String gap = (new Long( (long)Integer.MAX_VALUE )).toString();
String end = (new Long( ((long)Integer.MAX_VALUE) * 3L )).toString();
String mid = (new Long( ((long)Integer.MAX_VALUE) * 2L )).toString();
assertQ(f+": checking counts for lower",
req( "q", "id:[30 TO 60]"
,"rows", "0"
,"facet", "true"
,"facet.range", f
,"facet.range.start", start
,"facet.range.end", end
,"facet.range.gap", gap
,"facet.range.other", "all"
,"facet.range.include", "lower"
)
,"*[count("+pre+"/int)=3]"
,pre+"/int[@name='"+start+"'][.='6' ]"
,pre+"/int[@name='"+mid+"'][.='0' ]"
//
,meta+"/long[@name='end' ][.='"+end+"']"
,meta+"/int[@name='before' ][.='0']"
,meta+"/int[@name='after' ][.='0']"
,meta+"/int[@name='between'][.='6']"
);
}
private void helpTestWholeNumberRangeFacets(final String fieldName) { private void helpTestWholeNumberRangeFacets(final String fieldName) {
// the float test covers a lot of the weird edge cases // the float test covers a lot of the weird edge cases