I am querying a Solr core with this url:
select?q=*:*&rows=0&facet=on&facet.limit=-1&facet.mincount=0&facet.pivot=brand,series,sub_series
Using the Facet Pivot feature
Partial JSON response, notice how the fields are nested appropriately:
"facet_pivot":{
"brand,series,sub_series":[{
"field":"brand",
"value":"A. Lange & Sohne",
"count":69,
"pivot":[{
"field":"series",
"value":"1815 Manual Wind",
"count":1},
{
"field":"series",
"value":"1815 Up Down",
"count":1},
{
"field":"series",
"value":"Datograph",
"count":3,
"pivot":[{
"field":"sub_series",
"value":"Perpetual",
"count":2},
{
"field":"sub_series",
"value":"Up Down",
"count":1}]},
Now I replicate the same query with pySolr:
def nested_navbar():
result = solr.search('*:*', **{
'rows': '0',
'facet': 'on',
'facet.limit': '-1',
'facet.mincount': '0',
'facet.pivot': ['brand_exact', 'series_exact', 'sub_series_exact']
})
result = result.facets['facet_pivot']
return result
For some reason, when I print the data (pdb, or Django templates), the dictionary in the result has 3 different arrays for brands, series and sub_series, without the original nesting. In other words, the pivot field is gone.
Per matslindh's advice, I setup logging for pySolr:
export DEBUG_PYSOLR='true'
to terminal.Here is the link generated by pySolr:
/?q=%2A%3A%2A&rows=0&facet=on&facet.limit=-1&facet.mincount=0&facet.pivot=brand&facet.pivot=series&facet.pivot=sub_series&wt=json
The issue is that pySolr was creating a new facet.pivot
field for each item in the array ('brand', 'series' and 'sub_series').
My new code, which fixes the issue and generates a single facet.pivot
field:
'facet.pivot': 'brand,series,sub_series'