def sort_terms(facets):
    """Sort terms lexicographically instead of by the number of results
    returned. This will only sort 'terms' type facets."""
    for facet in facets:
        if facet['type'] == 'terms' and facet.get('buckets'):
            facet['buckets'].sort(key=lambda x: x['value'])
    return facets