<commit_before><?php

namespace Purjus\SearchBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Purjus\SearchBundle\Manager\SearchManager;
use FOS\RestBundle\Controller\Annotations\NoRoute;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use FOS\RestBundle\Request\ParamFetcher;
use Purjus\AdminBundle\Controller\PurjusTranslatableRESTController;

/**
 * Search controller.
 *
 * @author Purjus Communication
 * @author Tom
 *
 *
 */
class SearchController extends PurjusTranslatableRESTController
{

    /**
     * Display results or send them serialized.
     *
     * @NoRoute
     *
     * @param Request $request
     * @return Response|array
     */
    public function searchAction(Request $request, $term)
    {

        $results = $this->getResults($request, $term);

        $view = $this->view($results, 200)
            ->setTemplate('PurjusSearchBundle:Search:search.html.twig')
            ->setTemplateVar('results') // name of the "main" variable in the template
            ->setTemplateData(array(
                'term' => $term,
                'lang_alternates' => $this->getGenericLangAlternates($request, array('term' => $term)),
            ));

        return $this->handleView($view);

    }

    /**
     * @Post("search")
     * @RequestParam(name="term", requirements=".+", allowBlank=false, strict=true, description="Search term.")
     *
     * @param Request $request
     * @param ParamFetcher $paramFetcher
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function postSearchAction(Request $request, ParamFetcher $paramFetcher)
    {
        $response = $this->forward('PurjusSearchBundle:Search:search', array(
            'term'  => $paramFetcher->get('term'),
        ));

        return $response;
    }
<commit_msg>a HTML POST search redirect to the GET version<commit_after><?php

namespace Purjus\SearchBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Purjus\SearchBundle\Manager\SearchManager;
use FOS\RestBundle\Controller\Annotations\NoRoute;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use FOS\RestBundle\Request\ParamFetcher;
use Purjus\AdminBundle\Controller\PurjusTranslatableRESTController;

/**
 * Search controller.
 *
 * @author <NAME>
 * @author Tom
 *
 *
 */
class SearchController extends PurjusTranslatableRESTController
{

    /**
     * Display results or send them serialized.
     *
     * @NoRoute
     *
     * @param Request $request
     * @return Response|array
     */
    public function searchAction(Request $request, $term)
    {

        $results = $this->getResults($request, $term);

        $view = $this->view($results, 200)
            ->setTemplate('PurjusSearchBundle:Search:search.html.twig')
            ->setTemplateVar('results') // name of the "main" variable in the template
            ->setTemplateData(array(
                'term' => $term,
                'lang_alternates' => $this->getGenericLangAlternates($request, array('term' => $term)),
                'form_action' => $this->get('router')->generate('purjus_search_post'),
            ));

        return $this->handleView($view);

    }

    /**
     * @Post("search")
     * @RequestParam(name="term", requirements=".+", allowBlank=false, description="Search term.")
     *
     * @param Request $request
     * @param ParamFetcher $paramFetcher
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function postSearchAction(Request $request, ParamFetcher $paramFetcher)
    {

        $term = $paramFetcher->get('term');

        // if the form is posted, redirect to the GET route witht the term
        if ('html' === $request->getRequestFormat()) {
            $view = $this->routeRedirectView('purjus_search', array('term' => $term), 301);
            return $this->handleView($view);
        }

        $response = $this->forward('PurjusSearchBundle:Search:search', array(
            'term'  => $term,
        ));

        return $response;
    }

{'fraction_non_alphanumeric': 0.13211678832116788, 'fraction_numerical': 0.0021897810218978104, 'mean_word_length': 3.0146484375, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 37, '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': '3806136', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1177, 'n_words': 229}