<commit_before>import pysolr
from ckan.plugins.toolkit import get_or_bust, side_effect_free
from ckan.logic import ActionError
from ckan.lib.search.common import make_connection
import ckan.plugins.toolkit as tk

import logging
log = logging.getLogger(__name__)


@side_effect_free
def ogdzh_autosuggest(context, data_dict):
    """
    collecting autosuggestions from solr by calling
    :param q: the search term
           example: velo
    :param cfq: a context as facet-names concatenated by AND
           example: 'soziales AND bevolkerung'
    :return: autosuggestions that were generated by solr
             by the suggest handler
             as a list of unique suggestions
    """
    q = get_or_bust(data_dict, 'q')
    cfq = data_dict.get('cfq', '')

    if cfq:
        cfq = 'active AND %s' % cfq
    else:
        cfq = 'active'
    handler = '/suggest'
    suggester = 'default'
    suggest_search_limit = int(tk.config.get(
        'ckanext.stadtzh-theme.ogdzh_autosuggest_search_limit', 100))
    suggest_results_limit = int(tk.config.get(
        'ckanext.stadtzh-theme.ogdzh_autosuggest_result_limit', 10))

    log.debug(
        'Loading suggestions for {} (cfq: {}) with handler {}, '
        'suggester {}, result-limit {}, search-limit {}'
        .format(
           q, cfq, handler, suggester, suggest_results_limit,  suggest_search_limit
        ))

    try:
        solr = make_connection()
        results = solr.search(
            '',
            search_handler=handler,
            **{'suggest.q': q,
               'suggest.count': suggest_search_limit,
               'suggest.cfq': cfq}
        )
        suggestions = results.raw_response['suggest'][suggester].values()[0]
        log.debug("suggestions found: {}".format(suggestions))
        terms = \
            list(set([suggestion['term']
                      for suggestion
                      in suggestions['suggestions']]))[:suggest_results_limit]
        log.debug("suggestions found: {}".format(terms))
        return list(set(terms))
    except pysolr.SolrError as e:
        log.exception('Could not load suggestions from solr: %s' % e)
        raise ActionError('Error retrieving suggestions from solr')
<commit_msg>Fix too-long line<commit_after>import pysolr
from ckan.plugins.toolkit import get_or_bust, side_effect_free
from ckan.logic import ActionError
from ckan.lib.search.common import make_connection
import ckan.plugins.toolkit as tk

import logging
log = logging.getLogger(__name__)


@side_effect_free
def ogdzh_autosuggest(context, data_dict):
    """
    collecting autosuggestions from solr by calling
    :param q: the search term
           example: velo
    :param cfq: a context as facet-names concatenated by AND
           example: 'soziales AND bevolkerung'
    :return: autosuggestions that were generated by solr
             by the suggest handler
             as a list of unique suggestions
    """
    q = get_or_bust(data_dict, 'q')
    cfq = data_dict.get('cfq', '')

    if cfq:
        cfq = 'active AND %s' % cfq
    else:
        cfq = 'active'
    handler = '/suggest'
    suggester = 'default'
    suggest_search_limit = int(tk.config.get(
        'ckanext.stadtzh-theme.ogdzh_autosuggest_search_limit', 100))
    suggest_results_limit = int(tk.config.get(
        'ckanext.stadtzh-theme.ogdzh_autosuggest_result_limit', 10))

    log.debug(
        'Loading suggestions for {} (cfq: {}) with handler {}, '
        'suggester {}, result-limit {}, search-limit {}'
        .format(
            q, cfq, handler, suggester, suggest_results_limit,
            suggest_search_limit
        ))

    try:
        solr = make_connection()
        results = solr.search(
            '',
            search_handler=handler,
            **{'suggest.q': q,
               'suggest.count': suggest_search_limit,
               'suggest.cfq': cfq}
        )
        suggestions = results.raw_response['suggest'][suggester].values()[0]
        log.debug("suggestions found: {}".format(suggestions))
        terms = \
            list(set([suggestion['term']
                      for suggestion
                      in suggestions['suggestions']]))[:suggest_results_limit]
        log.debug("suggestions found: {}".format(terms))
        return list(set(terms))
    except pysolr.SolrError as e:
        log.exception('Could not load suggestions from solr: %s' % e)
        raise ActionError('Error retrieving suggestions from solr')

{'fraction_non_alphanumeric': 0.10506272401433692, 'fraction_numerical': 0.002688172043010753, 'mean_word_length': 2.5102201257861636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4376515', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1319, 'n_words': 322}