m3rg
m3rg

Reputation: 688

Count of Facets in Solr?

Is there a way to get the count of different facets in solr?

This is an example facet:

What I need to get here is "5" as in 5 different electronic items. Of course I can count the facet but some of them have many items inside and fetching and counting them really slow it down.

Upvotes: 3

Views: 8906

Answers (5)

Archana Udaranga
Archana Udaranga

Reputation: 1

Use this GET request:

http://localhost:8983/solr/core_name/select?json.facet={x:"unique(electronic_items)"}&q=*:*&rows=0

Upvotes: 0

John Meinken
John Meinken

Reputation: 469

Not an exact answer to this question, but if facet distinct count doesn't work for anyone, you can get that information using group.ngroups:

group = true
group.field = [field you are faceting on]
group.ngroups = true

The disadvantage of this approach is that if you want ungrouped results, you will have to run the query a second time.

Upvotes: 2

Rabotyahoff
Rabotyahoff

Reputation: 74

In SOLR 5.1 will be a "JSON Facet API" with function "unique(state)". http://yonik.com/solr-facet-functions/

Upvotes: 3

Stinger Guala
Stinger Guala

Reputation: 1

Of course the patch is recommended, but the cheesy way to do this for a simple facet, as you have here, is just to use the length of the facet divided by 2. For example, since you are faceting on type:

facetCount = facet_counts.facet_fields.type.length/2

Upvotes: 0

Jayendra
Jayendra

Reputation: 52779

You need to apply Solr Patch SOLR-2242 to get the Facet distinct count.

Upvotes: 4

Related Questions