Index out of bound exception on range facets when IncludeZeroCount = false, maxCount >
actual count
---------------------------------------------------------------------------------------------------
Key: HSEARCH-883
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-883
Project: Hibernate Search
Issue Type: Bug
Components: query
Affects Versions: 4.0.0.Alpha1, 3.4.1.Final
Reporter: Elmer van Chastelet
Attachments: FacetCollector.diff, RangeFacetingTest.diff
As reported in the mailing list.
I just upgraded to from HS 3.4.0 to 3.4.1.
When using range faceting with includeZeroCount=false AND setMaxCount is set higher than
the actual facets after filtering out the zero counts, I get this exception:
{code}
exception message: toIndex = 3
java.lang.IndexOutOfBoundsException: toIndex = 3
at java.util.ArrayList.subListRangeCheck(ArrayList.java:885)
at java.util.ArrayList.subList(ArrayList.java:877)
at
org.hibernate.search.query.collector.FacetCollector.createSortedFacetList(FacetCollector.java:139)
at
org.hibernate.search.query.collector.FacetCollector.getFacetList(FacetCollector.java:128)
at
org.hibernate.search.query.engine.impl.QueryHits.updateTopDocs(QueryHits.java:236)
at
org.hibernate.search.query.engine.impl.QueryHits.<init>(QueryHits.java:127)
at
org.hibernate.search.query.engine.impl.HSQueryImpl.getQueryHits(HSQueryImpl.java:419)
at
org.hibernate.search.query.engine.impl.HSQueryImpl.queryDocumentExtractor(HSQueryImpl.java:275)
at
org.hibernate.search.query.engine.impl.FacetManagerImpl.getFacets(FacetManagerImpl.java:111)
at
org.webdsl.search.AbstractEntitySearcher.getFacets(AbstractEntitySearcher.java:520)
{code}
This is introduced by the fix for
[
HSEARCH-776|https://hibernate.onjira.com/browse/HSEARCH-776]
Fix is easy and attached, just like an additional test.
see:
{code:java|title=FacetCollector.diff}
Index: FacetCollector.java
===================================================================
--- FacetCollector.java (revision 1712)
+++ FacetCollector.java (working copy)
@@ -136,7 +136,7 @@
facetList = createRangeFacetList( counter.getCounts().entrySet(), request,
counter.getCounts().size() );
Collections.sort( facetList, new RangeDefinitionOrderFacetComparator( ) );
if ( facetRequest.getMaxNumberOfFacets() > 0 ) {
- facetList = facetList.subList( 0, facetRequest.getMaxNumberOfFacets() );
+ facetList = facetList.subList( 0, Math.min( facetRequest.getMaxNumberOfFacets(),
facetList.size() ) );
}
}
else {
{code}
{code:java|title=Failing test}
public void testRangeQueryRangeDefOrderMaxCountWithoutZeroCount() {
FacetingRequest rangeRequest = queryBuilder( Fruit.class ).facet()
.name( priceRange )
.onField( indexFieldName )
.range()
.from( 0.00 ).to( 1.00 )
.from( 1.01 ).to( 1.50 )
.from( 1.51 ).to( 3.00 )
.from( 4.00 ).to( 5.00 )
.includeZeroCounts( false )
.orderedBy( FacetSortOrder.RANGE_DEFINITION_ODER )
.maxFacetCount(4)
.createFacetingRequest();
FullTextQuery query = createMatchAllQuery( Fruit.class );
FacetManager facetManager = query.getFacetManager();
facetManager.enableFaceting( rangeRequest );
List<Facet> facets = query.getFacetManager().getFacets( priceRange );
assertFacetCounts( facets, new int[] { 2, 3, 5 } );
assertEquals( "[0.0, 1.0]", facets.get( 0 ).getValue() );
assertEquals( "[1.01, 1.5]", facets.get( 1 ).getValue() );
assertEquals( "[1.51, 3.0]", facets.get( 2 ).getValue() );
}
{code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira