lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maahi333 <>
Subject Drill down facet using numhits as zero.
Date Wed, 12 Oct 2016 10:13:40 GMT

Is there a way by using FacetCollector to get the result with numhits as 0.
Below is the code that I am using for facet search.

FacetsCollector facetCollector = new FacetsCollector();, drillDownQuery, limit, facetCollector);

Here if we pass limit as 0 then we get error as "numHits must be > 0; please
use TotalHitCountCollector if you just need the total hit count"

So in order to have this fix I changed the code like 

FacetsCollector facetCollector = new FacetsCollector();
TopDocs topDocs = null;
TotalHitCountCollector totalHitCountCollector = null;
if (limit == 0) {
	totalHitCountCollector = new TotalHitCountCollector();
	topDocs =, filterQuery, first + limit,
	MultiCollector.wrap(totalHitCountCollector, facetCollector));
} else
	topDocs =, filterQuery, first + limit,

But there is difference in output when limit is 0 and limit is greater than

E.g. if we provide facet filter which does not fetch any record then for
limit greater than 0 which uses FacetCollector search we do not get any
facet information since result is not returned.

But for limit=0 we get facet information even though the result is not

View this message in context:
Sent from the Lucene - Java Developer mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message