def _generate_facet(config):
    """Make facet string for query from facet configurations.

    A facet configuration is a dictionary with specific fields.

    Facet can be of three types:

    1. field
    2. count
    3. pivot

    There are global configurations for all facet types. These are specified
    in the following fields:

    1. limit
    2. sort
    3. mincount

    For field type facet you must specify the following fields:

    1. field
        Field with which to bucketize documents. This field can be a list of
        fields.

    For range type facet you must specify the following fields:

    1. range
        Field with which to bucketize documents.
    2. start
    3. end
    4. step

    For pivot type facet you must specify the following fields:

    1. pivot
        List of fields with which to bucketize documents.

    For more information of faceting checkout the solr documentation:
    https://lucene.apache.org/solr/guide/6_6/faceting.html

    """
    if config is None:
        config = {}
    if len(config) == 0:
        return ''
    elements = ['facet=true']
    if 'field' in config:
        field = config['field']
        if not isinstance(field, (list, tuple)):
            field = [field]
        for field_ in field:
            elements.append('facet.field={}'.format(field_))
        if 'mincount' in config:
            mincount = config['mincount']
            elements.append('facet.mincount={}'.format(mincount))
    elif 'range' in config:
        field = config['range']
        elements.append('facet.range={}'.format(field))
        start = config['start']
        end = config['end']
        gap = config['gap']
        elements.extend(['facet.range.start={}'.format(start),
            'facet.range.end={}'.format(end), 'facet.range.gap={}'.format(gap)]
            )
        if 'mincount' in config:
            mincount = config['mincount']
            elements.append('facet.mincount={}'.format(mincount))
    elif 'pivot' in config:
        fields = config['pivot']
        elements.append('facet.pivot={}'.format(','.join(fields)))
        if 'mincount' in config:
            mincount = config['mincount']
            elements.append('facet.pivot.mincount={}'.format(mincount))
    if 'limit' in config:
        limit = config['limit']
        elements.append('facet.limit={}'.format(limit))
    if 'sort' in config:
        sortby = config['sort']
        elements.append('facet.sort={}'.format(sortby))
    return '&{}'.format('&'.join(elements))
