<commit_before><?php
namespace Search\Controller;

use Cake\Network\Exception\BadRequestException;
use Cake\ORM\Query;
use Cake\ORM\TableRegistry;
use Cake\Utility\Inflector;
use Search\Controller\AppController;

class SearchController extends AppController
{
    /**
     * Advanced search action
     *
     * @param string $model model name
     * @return void
     */
    public function advanced($model = null)
    {
        $this->_searchAction($model, true);
    }

    /**
     * Basic search action
     *
     * @param string $model model name
     * @return void
     */
    public function basic($model = null)
    {
        $this->_searchAction($model);
    }

    /**
     * Save action
     *
     * @param string|null $id Search id.
     * @return void Redirects to advanced action.
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
     */
    public function save($id = null)
    {
        $this->request->allowMethod(['patch', 'post', 'put']);
        $this->loadModel('Search.SavedSearches');
        $search = $this->SavedSearches->get($id);
        $search = $this->SavedSearches->patchEntity($search, $this->request->data);
        if ($this->SavedSearches->save($search)) {
            $this->Flash->success(__('The search has been saved.'));
        } else {
            $this->Flash->error(__('The search could not be saved. Please, try again.'));
        }
        return $this->redirect(['action' => 'advanced', $search->model]);
    }

    /**
     * Search action
     *
     * @param  string $model model name
     * @param  bool   $advanced advanced search flag
     * @return void
     */
    protected function _searchAction($model, $advanced = false)
    {
        if (is_null($model)) {
            throw new BadRequestException();
        }
        $modelName = Inflector::pluralize(Inflector::classify($model));

        if ($this->request->is('post')) {<commit_msg>saved result action (task #1596)<commit_after><?php
namespace Search\Controller;

use Cake\Network\Exception\BadRequestException;
use Cake\ORM\Query;
use Cake\ORM\TableRegistry;
use Cake\Utility\Inflector;
use Search\Controller\AppController;

class SearchController extends AppController
{
    /**
     * Advanced search action
     *
     * @param string $model model name
     * @return void
     */
    public function advanced($model = null)
    {
        $this->_searchAction($model, true);
    }

    /**
     * Basic search action
     *
     * @param string $model model name
     * @return void
     */
    public function basic($model = null)
    {
        $this->_searchAction($model);
    }

    /**
     * Save action
     *
     * @param string|null $id Search id.
     * @return void Redirects to advanced action.
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
     */
    public function save($id = null)
    {
        $this->request->allowMethod(['patch', 'post', 'put']);
        $this->loadModel('Search.SavedSearches');
        $search = $this->SavedSearches->get($id);
        $search = $this->SavedSearches->patchEntity($search, $this->request->data);
        if ($this->SavedSearches->save($search)) {
            $this->Flash->success(__('The search has been saved.'));
        } else {
            $this->Flash->error(__('The search could not be saved. Please, try again.'));
        }
        return $this->redirect(['action' => 'advanced', $search->model]);
    }

    /**
     * Saved result action
     *
     * @param  string $model model name
     * @param  string $id    record id
     * @return void
     */
    public function savedResult($model, $id)
    {
        $this->loadModel('Search.SavedSearches');
        $search = $this->SavedSearches->get($id);
        $this->set('entities', json_decode($search->content));
        $this->set('fields', $this->Searchable->getListingFields($model));
    }

    /**
     * Search action
     *
     * @param  string $model model name
     * @param  bool   $advanced advanced search flag
     * @return void
     */
    protected function _searchAction($model, $advanced = false)
    {
        if (is_null($model)) {
            throw new BadRequestException();
        }
        $modelName = Inflector::pluralize(Inflector::classify($model));

        if ($this->request->is('post')) {
{'fraction_non_alphanumeric': 0.1440443213296399, 'fraction_numerical': 0.0009233610341643582, 'mean_word_length': 2.4608626198083066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '956050', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1244, 'n_words': 290}