当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::addAggregation方法代码示例

本文整理汇总了PHP中Elastica\Query::addAggregation方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::addAggregation方法的具体用法?PHP Query::addAggregation怎么用?PHP Query::addAggregation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elastica\Query的用法示例。


在下文中一共展示了Query::addAggregation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: indexAction

 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);
 }
开发者ID:hasantayyar,项目名称:ojs,代码行数:60,代码来源:ExploreController.php

示例2: indexAction

 /**
  * @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);
 }
开发者ID:hasantayyar,项目名称:ojs,代码行数:60,代码来源:PeopleController.php

示例3: getStates

 protected function getStates()
 {
     $results = [];
     $query = new Elastica\Query();
     $query->setSize(0);
     $agg = new Elastica\Aggregation\Nested('states', 'state');
     $st_terms = new Elastica\Aggregation\Terms('abbrev');
     $st_terms->setField('state.abbrev');
     $st_terms->setOrder('_term', 'asc');
     $st_terms->setSize(0);
     $state_terms = new Elastica\Aggregation\Terms('full');
     $state_terms->setField('state.full');
     $st_terms->addAggregation($state_terms);
     $agg->addAggregation($st_terms);
     $query->addAggregation($agg);
     /* @var $elastica_client Elastica\Client */
     $elastica_client = $this->getServiceLocator()->getServiceLocator()->get('elastica-client');
     try {
         /* @var $response \Elastica\Response */
         $response = $elastica_client->request('usgeodb/locality/_search?query_cache=true', Request::GET, $query->toArray());
         $data = $response->getData();
         $aggregations = isset($data['aggregations']['states']['abbrev']['buckets']) ? $data['aggregations']['states']['abbrev']['buckets'] : [];
         foreach ($aggregations as $aggregation) {
             $key = strtoupper($aggregation['key']);
             $value = ucwords($aggregation['full']['buckets'][0]['key']);
             $results[$key] = $value;
         }
     } catch (\Exception $e) {
     }
     return $results;
 }
开发者ID:arstropica,项目名称:zf2-dashboard,代码行数:31,代码来源:LocationFieldset.php

示例4: testReverseNestedAggregation

 /**
  * @group functional
  */
 public function testReverseNestedAggregation()
 {
     $agg = new Nested('comments', 'comments');
     $names = new Terms('name');
     $names->setField('comments.name');
     $tags = new Terms('tags');
     $tags->setField('tags');
     $reverseNested = new ReverseNested('main');
     $reverseNested->addAggregation($tags);
     $names->addAggregation($reverseNested);
     $agg->addAggregation($names);
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_getIndexForTest()->search($query)->getAggregation('comments');
     $this->assertArrayHasKey('name', $results);
     $nameResults = $results['name'];
     $this->assertCount(3, $nameResults['buckets']);
     // bob
     $this->assertEquals('bob', $nameResults['buckets'][0]['key']);
     $tags = array(array('key' => 'foo', 'doc_count' => 2), array('key' => 'bar', 'doc_count' => 1), array('key' => 'baz', 'doc_count' => 1));
     $this->assertEquals($tags, $nameResults['buckets'][0]['main']['tags']['buckets']);
     // john
     $this->assertEquals('john', $nameResults['buckets'][1]['key']);
     $tags = array(array('key' => 'bar', 'doc_count' => 1), array('key' => 'foo', 'doc_count' => 1));
     $this->assertEquals($tags, $nameResults['buckets'][1]['main']['tags']['buckets']);
     // susan
     $this->assertEquals('susan', $nameResults['buckets'][2]['key']);
     $tags = array(array('key' => 'baz', 'doc_count' => 1), array('key' => 'foo', 'doc_count' => 1));
     $this->assertEquals($tags, $nameResults['buckets'][2]['main']['tags']['buckets']);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:33,代码来源:ReverseNestedTest.php

示例5: getStatsQuery

 private function getStatsQuery(Journal $journal)
 {
     $filter = new Term();
     $filter->setTerm('journal.id', $journal->getId());
     $filterQuery = new Filtered();
     $filterQuery->setFilter($filter);
     $query = new Query($filterQuery);
     $dateHistogram = new DateHistogram('dateHistogram', 'created', 'month');
     $dateHistogram->setFormat("YYYY-MM-dd");
     $query->addAggregation($dateHistogram);
     $genderAggregation = new Terms('language');
     $genderAggregation->setField('locale');
     $query->addAggregation($genderAggregation);
     $query->setSize(0);
     return $query;
 }
开发者ID:necatikartal,项目名称:ojs,代码行数:16,代码来源:ArticleReportController.php

示例6: testValueCountAggregation

 /**
  * @group functional
  */
 public function testValueCountAggregation()
 {
     $agg = new ValueCount('count', 'price');
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_getIndexForTest()->search($query)->getAggregation('count');
     $this->assertEquals(5, $results['value']);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:11,代码来源:ValueCountTest.php

示例7: testScriptedMetricAggregation

 /**
  * @group functional
  */
 public function testScriptedMetricAggregation()
 {
     $agg = new ScriptedMetric('scripted', "_agg['durations'] = [:]", "key = doc['start'].value+ \":\"+ doc['end'].value; _agg.durations[key] = doc['end'].value - doc['start'].value;", 'values = []; for (item in _agg.durations) { values.add(item.value) }; return values');
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_getIndexForTest()->search($query)->getAggregation('scripted');
     $this->assertEquals(array(100, 50, 150), $results['value'][0]);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:11,代码来源:ScriptedMetricTest.php

示例8: testDateHistogramAggregation

 public function testDateHistogramAggregation()
 {
     $agg = new DateHistogram("hist", "created", "1h");
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_index->search($query)->getAggregation("hist");
     $this->assertEquals(3, sizeof($results['buckets']));
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:8,代码来源:DateHistogramTest.php

示例9: testMissingAggregation

 /**
  * @group functional
  */
 public function testMissingAggregation()
 {
     $agg = new Missing('missing', 'color');
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_getIndexForTest()->search($query)->getAggregation('missing');
     $this->assertEquals(1, $results['doc_count']);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:11,代码来源:MissingTest.php

示例10: testValueCountAggregation

 public function testValueCountAggregation()
 {
     $agg = new ValueCount("count", "price");
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_index->search($query)->getAggregation("count");
     $this->assertEquals(5, $results['value']);
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:8,代码来源:ValueCountTest.php

示例11: testMissingAggregation

 public function testMissingAggregation()
 {
     $agg = new Missing("missing", "color");
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_index->search($query)->getAggregation("missing");
     $this->assertEquals(1, $results['doc_count']);
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:8,代码来源:MissingTest.php

示例12: testCardinalityAggregation

 public function testCardinalityAggregation()
 {
     $agg = new Cardinality("cardinality");
     $agg->setField("color");
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_index->search($query)->getAggregation("cardinality");
     $this->assertEquals(3, $results['value']);
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:9,代码来源:CardinalityTest.php

示例13: testSumAggregation

 public function testSumAggregation()
 {
     $agg = new Sum("sum");
     $agg->setField("price");
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_index->search($query)->getAggregation("sum");
     $this->assertEquals(5 + 8 + 1 + 3, $results['value']);
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:9,代码来源:SumTest.php

示例14: testSetOffsetWorks

 /**
  * @group functional
  */
 public function testSetOffsetWorks()
 {
     $agg = new DateHistogram('hist', 'created', '1m');
     $agg->setOffset('+40s');
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_getIndexForTest()->search($query)->getAggregation('hist');
     $this->assertEquals('2014-01-29T00:19:40.000Z', $results['buckets'][0]['key_as_string']);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:12,代码来源:DateHistogramTest.php

示例15: testMinAggregation

 public function testMinAggregation()
 {
     $agg = new Min("min_price");
     $agg->setField("price");
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_index->search($query)->getAggregation("min_price");
     $this->assertEquals(1, $results['value']);
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:9,代码来源:MinTest.php


注:本文中的Elastica\Query::addAggregation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。