<commit_before><?php

namespace Ojs\SiteBundle\Controller;

use Elastica\Aggregation;
use Elastica\Query;
use Pagerfanta\Adapter\ElasticaAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class ExploreController extends Controller
{
    public function indexAction(Request $request, $page = 1)
    {
        $getTypes = $request->query->get('type_filters');
        $getSubjects = $request->query->get('subject_filters');
        $getPublishers = $request->query->get('publisher_filters');
        $typeFilters = !empty($getTypes) ? explode(',', $getTypes) : [];
        $subjectFilters = !empty($getSubjects) ? explode(',', $getSubjects) : [];
        $publisherFilters = !empty($getPublishers) ? explode(',', $getPublishers) : [];

        $journalSearcher = $this->get('fos_elastica.index.search.journal');
        $boolQuery = new Query\Bool();

        $match = new Query\Match();
        $match->setField('status', 1);
        $boolQuery->addMust($match);

        $match = new Query\Match();
        $match->setField('published', true);
        $boolQuery->addMust($match);

        if (!empty($typeFilters) || !empty($subjectFilters) || !empty($publisherFilters)) {

            foreach ($typeFilters as $type) {
                $match = new Query\Match();
                $match->setField('publisher.publisherType.name', $type);
                $boolQuery->addMust($match);
            }

            foreach ($subjectFilters as $subject) {
                $match = new Query\Match();
                $match->setField('subjects.subject', $subject);
                $boolQuery->addMust($match);
            }

            foreach ($publisherFilters as $publisher) {
                $match = new Query\Match();
                $match->setField('publisher.name', $publisher);
                $boolQuery->addMust($match);
            }
        }

        $journalQuery = new Query($boolQuery);

        $typeAgg = new Aggregation\Terms('types');
        $typeAgg->setField('publisher.publisherType.name');
        $typeAgg->setOrder('_term', 'asc');
        $typeAgg->setSize(0);
        $journalQuery->addAggregation($typeAgg);

        $subjectAgg = new Aggregation\Terms('subjects');
        $subjectAgg->setField('subjects.subject');
        $subjectAgg->setOrder('_term', 'asc');
        $subjectAgg->setSize(0);
        $journalQuery->addAggregation($subjectAgg);

        $publisherAgg = new Aggregation\Terms('publishers');
        $publisherAgg->setField('publisher.name');
        $publisherAgg->setOrder('_term', 'asc');
        $publisherAgg->setSize(0);
        $journalQuery->addAggregation($publisherAgg);

        $adapter = new ElasticaAdapter($journalSearcher, $journalQuery);
        $pagerfanta = new Pagerfanta($adapter);<commit_msg>Bring the publisher filter of explore page back<commit_after><?php

namespace Ojs\SiteBundle\Controller;

use Elastica\Aggregation;
use Elastica\Query;
use Pagerfanta\Adapter\ElasticaAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class ExploreController extends Controller
{
    public function indexAction(Request $request, $page = 1)
    {
        $getTypes = $request->query->get('type_filters');
        $getSubjects = $request->query->get('subject_filters');
        $getPublishers = $request->query->get('publisher_filters');
        $typeFilters = !empty($getTypes) ? explode(',', $getTypes) : [];
        $subjectFilters = !empty($getSubjects) ? explode(',', $getSubjects) : [];
        $publisherFilters = !empty($getPublishers) ? explode(',', $getPublishers) : [];

        $journalSearcher = $this->get('fos_elastica.index.search.journal');
        $boolQuery = new Query\Bool();

        $match = new Query\Match();
        $match->setField('status', 1);
        $boolQuery->addMust($match);

        $match = new Query\Match();
        $match->setField('published', true);
        $boolQuery->addMust($match);

        if (!empty($typeFilters) || !empty($subjectFilters) || !empty($publisherFilters)) {

            foreach ($typeFilters as $type) {
                $match = new Query\Match();
                $match->setField('publisher.publisherType.name', $type);
                $boolQuery->addMust($match);
            }

            foreach ($subjectFilters as $subject) {
                $match = new Query\Match();
                $match->setField('subjects.subject', $subject);
                $boolQuery->addMust($match);
            }

            foreach ($publisherFilters as $publisher) {
                $match = new Query\Match();
                $match->setField('publisher.name.raw', $publisher);
                $boolQuery->addMust($match);
            }
        }

        $journalQuery = new Query($boolQuery);

        $typeAgg = new Aggregation\Terms('types');
        $typeAgg->setField('publisher.publisherType.name');
        $typeAgg->setOrder('_term', 'asc');
        $typeAgg->setSize(0);
        $journalQuery->addAggregation($typeAgg);

        $subjectAgg = new Aggregation\Terms('subjects');
        $subjectAgg->setField('subjects.subject');
        $subjectAgg->setOrder('_term', 'asc');
        $subjectAgg->setSize(0);
        $journalQuery->addAggregation($subjectAgg);

        $publisherAgg = new Aggregation\Terms('publishers');
        $publisherAgg->setField('publisher.name.raw');
        $publisherAgg->setOrder('_term', 'asc');
        $publisherAgg->setSize(0);
        $journalQuery->addAggregation($publisherAgg);

        $adapter = new ElasticaAdapter($journalSearcher, $journalQuery);
        $pagerfanta = new Pagerfanta($adapter);
{'fraction_non_alphanumeric': 0.1543554006968641, 'fraction_numerical': 0.0017421602787456446, 'mean_word_length': 2.8427041499330654, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '6340187', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1631, 'n_words': 262}