You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by maahi333 <ma...@gmail.com> on 2016/10/12 10:13:40 UTC

Drill down facet using numhits as zero.

HI,

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();
FacetsCollector.search(searcher, 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 = FacetsCollector.search(st.searcher, filterQuery, first + limit,
	MultiCollector.wrap(totalHitCountCollector, facetCollector));
} else
	topDocs = FacetsCollector.search(st.searcher, filterQuery, first + limit,
facetCollector);

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

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
present.








--
View this message in context: http://lucene.472066.n3.nabble.com/Drill-down-facet-using-numhits-as-zero-tp4300838.html
Sent from the Lucene - Java Developer mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Re: Drill down facet using numhits as zero.

Posted by maahi333 <ma...@gmail.com>.
Sorry for wrong version of code :( below is the correct code 

FacetsCollector facetCollector = new FacetsCollector();
TopDocs topDocs = null;
TotalHitCountCollector totalHitCountCollector = null;
if (limit == 0) {
	totalHitCountCollector = new TotalHitCountCollector();
	indexSearcher.search(query, MultiCollector.wrap(totalHitCountCollector,
facetCollector));
	topDocs = new TopDocs(totalHitCountCollector.getTotalHits(), new
ScoreDoc[0], Float.NaN);
} else
	topDocs = FacetsCollector.search(st.searcher, filterQuery, first + limit,
facetCollector);



Yes initially I was searching for search method same as in DrillSideways 
which takes query and collector but could not find one also I saw that it is
not possible to use FacetCollector search API since there is no provision of
having TotalHitCountCollector and because of which I wrote above code but
end result is not as per expected.



--
View this message in context: http://lucene.472066.n3.nabble.com/Drill-down-facet-using-numhits-as-zero-tp4300838p4300845.html
Sent from the Lucene - Java Developer mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Re: Drill down facet using numhits as zero.

Posted by Michael McCandless <lu...@mikemccandless.com>.
I think we should just make FacetsCollector robust if you pass a
limit=0?  Under the hood, it should use a TotalHitCountCollector
instead.  Can you open a Lucene Jira issue?
https://issues.apache.org/jira/browse/lucene

Alternatively, or maybe in addition, FacetsCollector should have
search methods that only take a Collector and not an "int n", so you
can pass your own TotalHitCountCollector.

In the limit=0 case you are still passing the same "int n" down to
FacetsCollector.search, as "first + limit", so shouldn't that case
also hit the same exception?

I'm not sure why you see different facet results in the two branches.

Mike McCandless

http://blog.mikemccandless.com


On Wed, Oct 12, 2016 at 6:13 AM, maahi333 <ma...@gmail.com> wrote:
> HI,
>
> 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();
> FacetsCollector.search(searcher, 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 = FacetsCollector.search(st.searcher, filterQuery, first + limit,
>         MultiCollector.wrap(totalHitCountCollector, facetCollector));
> } else
>         topDocs = FacetsCollector.search(st.searcher, filterQuery, first + limit,
> facetCollector);
>
> But there is difference in output when limit is 0 and limit is greater than
> 0.
>
> 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
> present.
>
>
>
>
>
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Drill-down-facet-using-numhits-as-zero-tp4300838.html
> Sent from the Lucene - Java Developer mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org