We're updating the issue view to help you get more done. 

maxFacetCount returns incorrect results when ordering a faceted query

Description

When putting a restriction on facets such as

1 FacetingRequest fr = qb.facet().name("name").onField("someField").discrete().orderedBy(FacetSortOrder.COUNT_DESC).maxFacetCount(10).includeZeroCounts(false).createFacetingRequest();


I would expect the facets with the top 10 results to be returned which appears to be true but it seems some are randomly missing (like the 10 are somehow spread across all results as opposed to the top ten). Removing the max restriction and only returning the first ten entries shows the correct results.

for example

1 2 3 4 5 QueryBuilder qb = ftEm.getSearchFactory().buildQueryBuilder().forEntity(WebResult.class).get(); FacetManager fm = query.getFacetManager() FacetingRequest fr = qb.facet().name("name").onField("someField.id").discrete().orderedBy(FacetSortOrder.COUNT_DESC).includeZeroCounts(false).createFacetingRequest(); fm.enableFaceting(fr); fm.getFacets("name").subList(0, endIndex);

The two code examples should return the exact same thing but the don't. The below code is my workaround but as you can imaging this could potentially take a dangerous amount of memory due to it effectively loading the entire index.

My WebResult class has OneToOne relations to various other objects (e.g. country)

Environment

hibernate 3.6.4, hibernate search 3.4

Status

Assignee

Unassigned

Reporter

Adrian Meredith

Components

Fix versions

Affects versions

3.4.0.Final

Priority

Critical