ManBearPig is still a threat.

-Kallin Nagelberg

-----Original Message-----
From: Jonathan Rochkind [mailto:rochk...@jhu.edu] 
Sent: Tuesday, July 27, 2010 7:44 PM
To: solr-user@lucene.apache.org
Subject: RE: How to 'filter' facet results

> Is there a way to tell Solr to only return a specific set of facet values?  I
> feel like the facet query must be able to do this, but I'm not really
> understanding the facet query.  In my specific case, I'd like to only see 
> facet
> values for the same values I pass in as query filters, i.e. if I run this 
> query:
>    fq=keyword:man OR keyword:bear OR keyword:pig
>    facet=on
>    facet.field:keyword

> then I only want it to return the facet counts for man, bear, and pig.  The
> resulting docs might have a number of different values for keyword, in 
> addition

For the general case of filtering facet values, I've wanted to do that too in 
more complex situations, and there is no good way I've found. 

For your very specific use case though, yeah, you can do it with facet.query.  
Leave out the facet.field, but instead:

facet.query=keyword:man
facet.query=keyword:bear
facet.query=keyword:pig

You'll get three facet.query results in the response, one each for man, bear, 
pig. 

Solr behind the scenes will kind of do three seperate 'sub-queries', one for 
each facet.query, but since the query itself should be cached, you shouldn't 
notice much difference. Especially if you have a warming query that facets on 
the keyword field (I'm never entirely sure when caches created by warming 
queries will be used by a facet.query, or if it depends on the facet method in 
use, but it can't hurt). 

Jonathan

Reply via email to