Reputation: 688
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
Reputation: 1
Use this GET request:
http://localhost:8983/solr/core_name/select?json.facet={x:"unique(electronic_items)"}&q=*:*&rows=0
Upvotes: 0
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
Reputation: 74
In SOLR 5.1 will be a "JSON Facet API" with function "unique(state)". http://yonik.com/solr-facet-functions/
Upvotes: 3
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