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.publisher_type.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.publisher_type.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); $pagerfanta->setMaxPerPage(21); $pagerfanta->setCurrentPage($page); $journals = $pagerfanta->getCurrentPageResults(); $types = $adapter->getResultSet()->getAggregation('types')['buckets']; $subjects = $adapter->getResultSet()->getAggregation('subjects')['buckets']; $publishers = $adapter->getResultSet()->getAggregation('publishers')['buckets']; $data = ['types' => $types, 'subjects' => $subjects, 'publishers' => $publishers, 'type_filters' => $typeFilters, 'subject_filters' => $subjectFilters, 'publisher_filters' => $publisherFilters, 'journals' => $journals, 'pagerfanta' => $pagerfanta, 'page' => 'explore']; return $this->render('OjsSiteBundle:Explore:index.html.twig', $data); }
public function publisherAction(Request $request, $page = 1) { $getTypes = $request->query->get('type_filters'); $typeFilters = !empty($getTypes) ? explode(',', $getTypes) : []; $publisherSearcher = $this->get('fos_elastica.index.search.publisher'); $boolQuery = new Query\Bool(); if (!empty($typeFilters)) { foreach ($typeFilters as $type) { $match = new Query\Match(); $match->setField('publisherType', $type); $boolQuery->addMust($match); } } $publisherQuery = new Query($boolQuery); $typeAgg = new Aggregation\Terms('types'); $typeAgg->setField('publisherType'); $typeAgg->setOrder('_term', 'asc'); $typeAgg->setSize(0); $publisherQuery->addAggregation($typeAgg); $adapter = new ElasticaAdapter($publisherSearcher, $publisherQuery); $pagerfanta = new Pagerfanta($adapter); $pagerfanta->setMaxPerPage(20); $pagerfanta->setCurrentPage($page); $publishers = $pagerfanta->getCurrentPageResults(); $types = $adapter->getResultSet()->getAggregation('types')['buckets']; $data = ['types' => $types, 'page' => 'ojs_site_explore_publisher', 'publishers' => $publishers, 'pagerfanta' => $pagerfanta, 'type_filters' => $typeFilters]; return $this->render('OjsSiteBundle:Explore:publisher.html.twig', $data); }
/** * @param Request $request * @param int $page * @return \Symfony\Component\HttpFoundation\Response */ public function indexAction(Request $request, $page = 1) { $getRoles = $request->query->get('role_filters'); $getSubjects = $request->query->get('subject_filters'); $getJournals = $request->query->get('journal_filters'); $roleFilters = !empty($getRoles) ? explode(',', $getRoles) : []; $subjectFilters = !empty($getSubjects) ? explode(',', $getSubjects) : []; $journalFilters = !empty($getJournals) ? explode(',', $getJournals) : []; $userSearcher = $this->get('fos_elastica.index.search.user'); $userQuery = new Query('*'); if (!empty($roleFilters) || !empty($subjectFilters) || !empty($journalFilters)) { $boolQuery = new Query\Bool(); foreach ($roleFilters as $role) { $match = new Query\Match(); $match->setField('journalUsers.roles', $role); $boolQuery->addMust($match); } foreach ($subjectFilters as $subject) { $match = new Query\Match(); $match->setField('subjects', $subject); $boolQuery->addMust($match); } foreach ($journalFilters as $journal) { $match = new Query\Match(); $match->setField('journalUsers.journal.title', $journal); $boolQuery->addMust($match); } $userQuery->setQuery($boolQuery); } $roleAgg = new Aggregation\Terms('roles'); $roleAgg->setField('journalUsers.roles'); $roleAgg->setOrder('_term', 'asc'); $roleAgg->setSize(0); $userQuery->addAggregation($roleAgg); $subjectAgg = new Aggregation\Terms('subjects'); $subjectAgg->setField('subjects'); $subjectAgg->setOrder('_term', 'asc'); $subjectAgg->setSize(0); $userQuery->addAggregation($subjectAgg); $journalAgg = new Aggregation\Terms('journals'); $journalAgg->setField('journalUsers.journal.title'); $journalAgg->setOrder('_term', 'asc'); $journalAgg->setSize(0); $userQuery->addAggregation($journalAgg); $adapter = new ElasticaAdapter($userSearcher, $userQuery); $pagerfanta = new Pagerfanta($adapter); $pagerfanta->setMaxPerPage(20); $pagerfanta->setCurrentPage($page); $people = $pagerfanta->getCurrentPageResults(); $roles = $adapter->getResultSet()->getAggregation('roles')['buckets']; $subjects = $adapter->getResultSet()->getAggregation('subjects')['buckets']; $journals = $adapter->getResultSet()->getAggregation('journals')['buckets']; $data = ['people' => $people, 'roles' => $roles, 'subjects' => $subjects, 'journals' => $journals, 'pagerfanta' => $pagerfanta, 'role_filters' => $roleFilters, 'subject_filters' => $subjectFilters, 'journal_filters' => $journalFilters, 'page' => 'ojs_site_people_index']; return $this->render('OjsSiteBundle:People:index.html.twig', $data); }
public function testGetNbResults() { $this->resultSet->expects($this->once())->method('getTotalHits')->will($this->returnValue(100)); $this->assertSame(100, $this->adapter->getNbResults()); }