def detailed_response_mapper(solr_response):
    """
    Response mapper that also extracts the returned facets into a dict. In
    order to keep the sort order, a separate list contains the keys for the
    facet dictionary in sorted order.
    """
    result = {
        'docs': [],
        'numFound': 0
    }

    if 'response' in solr_response:
        result['numFound'] = solr_response['response']['numFound']
        result['docs'] = solr_response['response']['docs']

    if 'facet_counts' in solr_response:

        result['facet'] = {}
        facets = solr_response['facet_counts']

        if 'facet_fields' in facets:
            result['facet']['field'] = rf = {}
            for field in facets['facet_fields']:
                rf[field] = _flatten_to_dict(facets['facet_fields'][field])

        if 'facet_queries' in facets:
            result['facet']['query'] = rq = {}
            for query in facets['facet_queries']:
                rq[query] = _flatten_to_dict(facets['facet_queries'][query])

        if 'facet_ranges' in facets:
            result['facet']['range'] = rr = {}
            for frange in facets['facet_ranges']:
                rr[frange] = \
                    _flatten_to_dict(facets['facet_ranges'][frange]['counts'])
                rr[frange]['start'] = facets['facet_ranges'][frange]['start']
                rr[frange]['end'] = facets['facet_ranges'][frange]['end']
                rr[frange]['gap'] = facets['facet_ranges'][frange]['gap']

    return result
dataset/ETHPy150Open truemped/dopplr/dopplr/solr/responsemapper.py/detailed_response_mapper/original