<commit_before><?php
namespace Vanio\DomainBundle\Specification;

use Doctrine\ORM\QueryBuilder;
use Happyr\DoctrineSpecification\Filter\Filter;

class TextSearchQuery extends TextSearchSpecification implements Filter
{
    /** @var bool */
    private static $searchConfigurationSetUp = false;

    /** @var string */
    private $searchTerm;

    /** @var string */
    private $searchDocumentField;

    /** @var string|null */
    private $dqlAlias;

    public function __construct(
        string $searchTerm,
        string $searchDocumentField = 'searchDocument',
        string $dqlAlias = null
    ) {
        $this->searchTerm = $searchTerm;
        $this->searchDocumentField = $searchDocumentField;
        $this->dqlAlias = $dqlAlias;
    }

    /**
     * @param QueryBuilder $queryBuilder
     * @param string $dqlAlias
     * @return string
     */
    public function getFilter(QueryBuilder $queryBuilder, $dqlAlias): string
    {
        if (!self::$searchConfigurationSetUp) {
            $this->setUpSearchConfiguration($queryBuilder);
        }

        $queryBuilder->setParameter('_searchQuery', $this->processSearchTerm($this->searchTerm));

        return sprintf(
            'TSQUERY(%s.%s, :_searchQuery) = true',
            $this->dqlAlias ?? $dqlAlias,
            $this->searchDocumentField
        );
    }

    /**
     * @param QueryBuilder $queryBuilder
     */
    private function setUpSearchConfiguration(QueryBuilder $queryBuilder)
    {
        /*$db = $queryBuilder->getEntityManager()->getConnection();
        if (!$db->fetchColumn("SELECT true FROM pg_ts_dict WHERE dictname = 'cs'")) {
            $db->query('CREATE TEXT SEARCH DICTIONARY cs (template=ispell, dictfile = czech, afffile=czech, stopwords=czech)');
            $db->query('CREATE TEXT SEARCH CONFIGURATION ru (copy=english)');
            $db->query('ALTER TEXT SEARCH CONFIGURATION ru ALTER MAPPING FOR word, asciiword WITH cs, simple');
        }*/

        self::$searchConfigurationSetUp = true;
    }
}<commit_msg>Removed text search configuration setup from TextSearchQuery<commit_after><?php
namespace Vanio\DomainBundle\Specification;

use Doctrine\ORM\QueryBuilder;
use Happyr\DoctrineSpecification\Filter\Filter;

class TextSearchQuery extends TextSearchSpecification implements Filter
{
    /** @var string */
    private $searchTerm;

    /** @var string */
    private $searchDocumentField;

    /** @var string|null */
    private $dqlAlias;

    public function __construct(
        string $searchTerm,
        string $searchDocumentField = 'searchDocument',
        string $dqlAlias = null
    ) {
        $this->searchTerm = $searchTerm;
        $this->searchDocumentField = $searchDocumentField;
        $this->dqlAlias = $dqlAlias;
    }

    /**
     * @param QueryBuilder $queryBuilder
     * @param string $dqlAlias
     * @return string
     */
    public function getFilter(QueryBuilder $queryBuilder, $dqlAlias): string
    {
        $queryBuilder->setParameter('_searchQuery', $this->processSearchTerm($this->searchTerm));

        return sprintf(
            'TSQUERY(%s.%s, :_searchQuery) = true',
            $this->dqlAlias ?? $dqlAlias,
            $this->searchDocumentField
        );
    }
}
{'fraction_non_alphanumeric': 0.11770157553290084, 'fraction_numerical': 0.0, 'mean_word_length': 2.8965102286401927, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '343104', 'n_tokens_mistral': 907, 'n_tokens_neox': 892, 'n_words': 195}