MaticDiba
MaticDiba

Reputation: 905

Solr - returning counts for facets specified in query

I would like to create a query that will return facet counts for some field values even if that value count is 0. But on the other hand I don't want counts for the values that were not in the original query.

For example if I use in my query:

<arr name="fq">
    <str>Field:(4 OR 5)</str>
</arr>

I and there exists no document with the value 5 in this field, I would like to get back:

<lst name="facet_fields">
   <lst name="VersionStatus">
      <int name="4">2</int>
      <int name="5">0</int>
   </lst>
</lst>

But there shouldn't be counts for other values (ex. 1, 2, 3, ...), because they weren't spcified in the query.

Is that even possible? I was trying to achieve that with missing=true parameter, but that didn't work.

Upvotes: 0

Views: 409

Answers (1)

Persimmonium
Persimmonium

Reputation: 15789

instead of faceting on the field with 'facet.field' you can use N facet.query params, matching the terms in your fq, so, in your example:

&facet.query=Field:4&facet.query=Field:5

Upvotes: 1

Related Questions