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 "Harsch, Timothy J. (ARC-SC)[PEROT SYSTEMS]" <ti...@nasa.gov> on 2009/04/14 21:43:08 UTC

Distinct terms in facet field

How could I get a count of distinct terms for a given query?  For example:
The Wiki page
http://wiki.apache.org/solr/SimpleFacetParameters
has a section "Facet Fields with No Zeros"
which shows the query:
http://localhost:8983/solr/select?q=ipod&rows=0&facet=true&facet.limit=-1&facet.field=cat&facet.mincount=1&facet.field=inStock
and returns results where the inStock field has two facet counts (false is 3, and true is 1)

But what I would want to know is how many distinct values were found ( in this case it would be 2 / true and false ).  I realize I could count the number of terms returned, but if the set were large that would be non-performant.  Is there a better way?

Thanks,
Tim

Re: Distinct terms in facet field

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
On Wed, Apr 15, 2009 at 1:13 AM, Harsch, Timothy J. (ARC-SC)[PEROT SYSTEMS]
<ti...@nasa.gov> wrote:

> How could I get a count of distinct terms for a given query?  For example:
> The Wiki page
> http://wiki.apache.org/solr/SimpleFacetParameters
> has a section "Facet Fields with No Zeros"
> which shows the query:
>
> http://localhost:8983/solr/select?q=ipod&rows=0&facet=true&facet.limit=-1&facet.field=cat&facet.mincount=1&facet.field=inStock
> and returns results where the inStock field has two facet counts (false is
> 3, and true is 1)
>
> But what I would want to know is how many distinct values were found ( in
> this case it would be 2 / true and false ).  I realize I could count the
> number of terms returned, but if the set were large that would be
> non-performant.  Is there a better way?
>

To do this with facets, you'd need to return all of them. The other way of
doing this is by making a request to /admin/luke?fl=inStock which will
return the number of unique terms in that field.

http://wiki.apache.org/solr/LukeRequestHandler

You can also index the number of unique values in a field as a separate
field.

-- 
Regards,
Shalin Shekhar Mangar.