1
votes

My SOLR application features faceting on a "descendant_path" field. The number of facet can be great (eg 100) and I don't find it useful. So I would better have X (eg 2) facets and an extra one labelled "others".

So far I have :

 - set an unlimited number of facets (with facet.limit = -1), 
 - sorted them in decreasing count (with facet.sort = count), 
 - taken the first X (eg 2) elements
 - added the counts of the next elements together to form the "others" count

because I could not find a Solr faceting parameter that could do that.

Consequently not to reinvent the wheel, I need to know if there is already a Solr parameter that can return the sum of all the facet counts that are not returned within the facet.limit ?

For example if Solr returns 5 facets with facet.limit = -1
A (34) B (30) C (28) D (10) E (4)

If now I set the facet.limit = 2 it will return A (34) B (30)

Is there a parameter that returns the sum of all the counts from the facets that are not included (ie counts of C, D and E together) => Others (42) ?

Please note : facet.missing did not do the trick since it deals with documents with missing category not document with missing facet.

Is there really no parameter to achieve my goal or I simply missed it ?

Any help appreciated

1

1 Answers

1
votes

There is no built-in property other to give you this calculation.

However, it is easy to calculate, using the formula:

(numFound - sum(facet_counts)) - missing

In the following resultset:

{ 
   "responseHeader":{ 
      "zkConnected":true,
      "status":0,
      "QTime":39,
      "params":{ 
         "q":"post_content:term",
         "facet.field":"my_terms",
         "facet.missing":"true",
         "fq":"date:[2018-12-11T00:00:00Z TO 2019-12-10T23:59:59Z]",
         "facet.mincount":"3",
         "rows":"0",
         "facet":"true",
         "wt":"json"
      }
   },
   "response":{ 
      "numFound":3883,
      "start":0,
      "maxScore":10.545702,
      "docs":[ ..
      ]
   },
   "facet_counts":{ 
      "facet_fields":{ 
         "my_terms":{ 
            "someterm":59,
            "anotherterm":43,
            "yetanotherterm":55,
            "":323
         }
      },
   }
}

So we have:

(3883 - (59 + 43 + 55)) - 323 = 3403

Other = 3403