You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by David Thompson <gu...@yahoo.com> on 2010/07/28 01:25:04 UTC

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 
to those specified in the filter because keyword is a multiValued field.  How 
can I tell it to only return the facet values for man, bear, and pig?  On the 
client side I could programmatically remove the other facets that I don't care 
about, except that the resulting docs could return hundreds of different 
values.  If I were faceting on a single value, I could say facet.prefix=man, and 
that would work, but mostly I need this to work for more than one filter value.  
Is there a way to set multiple facet.prefix values?  Any ideas?

-dKt



      

RE: How to 'filter' facet results

Posted by "Nagelberg, Kallin" <KN...@globeandmail.com>.
ManBearPig is still a threat.

-Kallin Nagelberg

-----Original Message-----
From: Jonathan Rochkind [mailto:rochkind@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


RE: How to 'filter' facet results

Posted by Jonathan Rochkind <ro...@jhu.edu>.
> 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