<commit_before><?php
namespace Mapbender\CoreBundle\Element;

use Mapbender\CoreBundle\Component\Element;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
 * Simple Search - Just type, select and show result
 *
 * @author <NAME>
 */
class SimpleSearch extends Element
{
    /**
     * @inheritdoc
     */
    static public function getClassTitle()
    {
        return "mb.core.simplesearch.class.title";
    }

    /**
     * @inheritdoc
     */
    static public function getClassDescription()
    {
        return "mb.core.simplesearch.class.description";
    }

    /**
     * @inheritdoc
     */
    static public function getClassTags()
    {
        return array(
            "mb.core.search.tag.search");
    }

    /**
     * @inheritdoc
     */
    static public function listAssets()
    {
        return array(
            'js' => array(
                '@FOMCoreBundle/Resources/public/js/widgets/autocomplete.js',
                '@MapbenderCoreBundle/Resources/public/mapbender.element.simplesearch.js',
                ),
            'css' => array(),
            'trans' => array());
    }

    /**
     * @inheritdoc
     */
    public static function getType()
    {
        return 'Mapbender\CoreBundle\Element\Type\SimpleSearchAdminType';
    }

    /**
     * @inheritdoc
     */
    public static function getFormTemplate()
    {
        return 'MapbenderCoreBundle:ElementAdmin:simplesearch.html.twig';
    }

    /**
     * @inheritdoc
     */
    public static function getDefaultConfiguration()
    {
        return array(
            'query_url' => 'http://',
            'query_key' => 'q',
            'query_format' => '%s',
            'token_regex' => '[^<KEY>
            'token_regex_in' => '([<KEY>',
            'token_regex_out' => '$1*',
            'collection_path' => '',
            'label_attribute' => 'label',
            'geom_attribute' => 'geom',
            'geom_format' => 'WKT',
            'delay' => 300);
    }

    /**
     * @inheritdoc
     */
    public function getWidgetName()
    {
        return 'mapbender.mbSimpleSearch';
    }

    /**
     * @inheritdoc
     */
    public function render()
    {
        return $this->container->get('templating')
                ->render('MapbenderCoreBundle:Element:simplesearch.html.twig',
                    array(
                    'id' => $this->getId(),
                    'title' => $this->getTitle(),
                    'configuration' => $this->getConfiguration()));
    }

    /**
     * @inheritdoc
     */
    public function httpAction($action) {
        $configuration = $this->getConfiguration();

        $q = $this->container->get('request')->get('term', '');
        $qf = $configuration['query_format'] ? $configuration['query_format'] : '%s';

        // Replace Whitespace if desired
        if(array_key_exists('query_ws_replace', $configuration)) {
            $pattern = $configuration['query_ws_replace'];
            if('' !== trim($pattern)) {
                $q = preg_replace( '/\s+/', $pattern, $q);
            }
        }

        // Build query URL
        $url = $configuration['query_url'];
        $url .= (false === strpos($url, '?') ? '?' : '&');
        $url .= $configuration['query_key'] . '=' . sprintf($qf, $q);

        $path = array(
            '_controller' => 'OwsProxy3CoreBundle:OwsProxy:genericProxy',
            'url' => $url
        );
        $subRequest = $this->container->get('request')->duplicate(array(), null, $path);
        $response = $this->container->get('http_kernel')->handle(
                $subRequest, HttpKernelInterface::SUB_REQUEST);
        // Dive into result JSON if needed (Solr for example 'response.docs')
        if('' !== $configuration['collection_path']) {
            $data = json_decode($response->getContent(), true);
            foreach(explode('.', $configuration['collection_path']) as $key) {
                $data = $data[$key];
            }
            $response->setContent(json_encode($data));
        }

        // In dev environment, add query URL as response header for easier debugging
        if($this->container->get('kernel')->isDebug()) {
            $response->headers->set('X-Mapbender-SimpleSearch-URL', $url);
        }

        return $response;
    }
}
<commit_msg>changed regexp<commit_after><?php
namespace Mapbender\CoreBundle\Element;

use Mapbender\CoreBundle\Component\Element;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
 * Simple Search - Just type, select and show result
 *
 * @author <NAME>
 */
class SimpleSearch extends Element
{
    /**
     * @inheritdoc
     */
    static public function getClassTitle()
    {
        return "mb.core.simplesearch.class.title";
    }

    /**
     * @inheritdoc
     */
    static public function getClassDescription()
    {
        return "mb.core.simplesearch.class.description";
    }

    /**
     * @inheritdoc
     */
    static public function getClassTags()
    {
        return array(
            "mb.core.search.tag.search");
    }

    /**
     * @inheritdoc
     */
    static public function listAssets()
    {
        return array(
            'js' => array(
                '@FOMCoreBundle/Resources/public/js/widgets/autocomplete.js',
                '@MapbenderCoreBundle/Resources/public/mapbender.element.simplesearch.js',
                ),
            'css' => array(),
            'trans' => array());
    }

    /**
     * @inheritdoc
     */
    public static function getType()
    {
        return 'Mapbender\CoreBundle\Element\Type\SimpleSearchAdminType';
    }

    /**
     * @inheritdoc
     */
    public static function getFormTemplate()
    {
        return 'MapbenderCoreBundle:ElementAdmin:simplesearch.html.twig';
    }

    /**
     * @inheritdoc
     */
    public static function getDefaultConfiguration()
    {
        return array(
            'query_url' => 'http://',
            'query_key' => 'q',
            'query_format' => '%s',
            'token_regex' => '[^<KEY>
            'token_regex_in' => '([<KEY>3,})',
            'token_regex_out' => '$1*',
            'collection_path' => '',
            'label_attribute' => 'label',
            'geom_attribute' => 'geom',
            'geom_format' => 'WKT',
            'delay' => 300);
    }

    /**
     * @inheritdoc
     */
    public function getWidgetName()
    {
        return 'mapbender.mbSimpleSearch';
    }

    /**
     * @inheritdoc
     */
    public function render()
    {
        return $this->container->get('templating')
                ->render('MapbenderCoreBundle:Element:simplesearch.html.twig',
                    array(
                    'id' => $this->getId(),
                    'title' => $this->getTitle(),
                    'configuration' => $this->getConfiguration()));
    }

    /**
     * @inheritdoc
     */
    public function httpAction($action) {
        $configuration = $this->getConfiguration();

        $q = $this->container->get('request')->get('term', '');
        $qf = $configuration['query_format'] ? $configuration['query_format'] : '%s';

        // Replace Whitespace if desired
        if(array_key_exists('query_ws_replace', $configuration)) {
            $pattern = $configuration['query_ws_replace'];
            if('' !== trim($pattern)) {
                $q = preg_replace( '/\s+/', $pattern, $q);
            }
        }

        // Build query URL
        $url = $configuration['query_url'];
        $url .= (false === strpos($url, '?') ? '?' : '&');
        $url .= $configuration['query_key'] . '=' . sprintf($qf, $q);

        $path = array(
            '_controller' => 'OwsProxy3CoreBundle:OwsProxy:genericProxy',
            'url' => $url
        );
        $subRequest = $this->container->get('request')->duplicate(array(), null, $path);
        $response = $this->container->get('http_kernel')->handle(
                $subRequest, HttpKernelInterface::SUB_REQUEST);
        // Dive into result JSON if needed (Solr for example 'response.docs')
        if('' !== $configuration['collection_path']) {
            $data = json_decode($response->getContent(), true);
            foreach(explode('.', $configuration['collection_path']) as $key) {
                $data = $data[$key];
            }
            $response->setContent(json_encode($data));
        }

        // In dev environment, add query URL as response header for easier debugging
        if($this->container->get('kernel')->isDebug()) {
            $response->headers->set('X-Mapbender-SimpleSearch-URL', $url);
        }

        return $response;
    }
}

{'fraction_non_alphanumeric': 0.15667088753309544, 'fraction_numerical': 0.0012662599286289858, 'mean_word_length': 1.9814687714481811, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 93, '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': '1454535', 'n_tokens_mistral': 2505, 'n_tokens_neox': 2445, 'n_words': 429}