Range facets: .below on numeric null values (AssertionFailure: Unsupported range type)

Description

An assertion failure ("Unsupported range type") is thrown, when getting facets ( facetmanager.getFacets( facetName ) ) after narrowing on a facet ( facetmanager.getFacetGroup( facetingName ).selectFacets( facet )) in the following situation:

  • Using a range facet with .below constraint

  • on a numeric field (i.e. has @NumericField annotation)

  • the field has a null value for at least one indexed entity

Attached is a unit test that throws this exception.
My guess is that entities with null values are included in the result of the below facet, so probably null is evaluated to be 'lower' than any valid Integer. The lowest value found is probably used somewhere to set some range during .selectFacets( facetName ). This range is then used again when calling .getFacets( facetingName ), which tries to obtain the type from a null value -> AssertionFailure: Unsupported range type.

RangeFacetNumericNullValueFail.zip includes a unit test (testRangeBelowWithNullValues() in org.hibernate.search.test.query.facet.RangeFacetingTest) and the modified files which are used by this test (like Truck.java)

Exception trace:

org.hibernate.annotations.common.AssertionFailure: Unsupported range type at org.hibernate.search.query.dsl.impl.RangeFacetImpl.createNumericRangeQuery(RangeFacetImpl.java:146) at org.hibernate.search.query.dsl.impl.RangeFacetImpl.getFacetQuery(RangeFacetImpl.java:55) at org.hibernate.search.query.engine.impl.FacetManagerImpl.createSelectionGroupQuery(FacetManagerImpl.java:160) at org.hibernate.search.query.engine.impl.FacetManagerImpl.getFacetFilter(FacetManagerImpl.java:146) at org.hibernate.search.query.engine.impl.HSQueryImpl.buildFilters(HSQueryImpl.java:650) at org.hibernate.search.query.engine.impl.HSQueryImpl.getQueryHits(HSQueryImpl.java:384) at org.hibernate.search.query.engine.impl.HSQueryImpl.queryDocumentExtractor(HSQueryImpl.java:275) at org.hibernate.search.query.engine.impl.FacetManagerImpl.getFacets(FacetManagerImpl.java:110)

See also: topic in Hibernate user forum

Attachments

1
  • 19 May 2011, 01:40 PM

Activity

Hardy FerentschikAugust 11, 2011 at 6:52 PM

Hi Elmer,

thanks again for your help. You are really pointing out two issues. The first is the AssertionFailure which indeed can be fixed by using getNonNullMinOrMax().
The problem with 'null' is another issue and reveals a problem with the current implementation of faceting using the FacetingCollector. The FieldCache for numeric values uses primitive types which means the fact that there were null values is effectively lost. The array will contain the value 0 and that's what's counted. When you then select the facet a RangeQuery is executed selecting the values in the range. Since null null values are not even indexed they won't be retrieved.
The best solution in the long term is to switch to the new Lucene faceting API once it is available - HSEARCH-809.

Elmer van ChasteletMay 19, 2011 at 2:30 PM

I can think of 2 fixes at the moment:
Fix 1: in RangeFacetImpl.createNumericRangeQuery(), if range.getMin() is null -> use range.getMax, just like in .getFacetQuery(): Object minOrMax = getNonNullMinOrMax( range );
This does fix the exception problem (I just tested it), but reveals a new issue: the Facet count before narrowing include null values (that is, 6 matches before narrowing) and after narrowing null values are not included in the facet count (that is, 4 matches after narrowing) in the supplied unit test.
Fix 2: Don't include null values at all, or better: let is become a parameter just like 'includeZeroCounts'.

Hardy FerentschikMay 19, 2011 at 1:51 PM

Thanks for the bug report. I'll look into it asap.

Fixed

Details

Assignee

Reporter

Components

Affects versions

Priority

Created May 19, 2011 at 1:40 PM
Updated September 11, 2011 at 6:21 PM
Resolved August 11, 2011 at 9:17 PM

Flag notifications