count() public method

public count ( mixed $query = '', $fullResult = false ) : integer | ResultSet
$query mixed
$fullResult (default = false) By default only the total hit count is returned. If set to true, the full ResultSet including aggregations is returned
return integer | ResultSet
 /**
  * Get Query Count
  *
  * @param string $index        	
  * @param string $type        	
  *
  * @return number
  */
 public function getElasticaCount($index = false, $type = false)
 {
     $elastica_query = new Query();
     $elastica_client = $this->getElasticaClient();
     // If you want to restrict your search to a particular index then get
     // that
     $elastica_index = $index ? $elastica_client->getIndex($index) : false;
     // If you want to restrict your search to a particular type then get
     // that
     $elastica_type = $elastica_index && $type ? $elastica_index->getType($type) : false;
     $elastica_search = new Search($elastica_client);
     if ($elastica_index) {
         $elastica_search->addIndex($elastica_index);
     }
     if ($elastica_type) {
         $elastica_search->addType($elastica_type);
     }
     return $elastica_search->count($elastica_query);
 }
Example #2
0
 /**
  * @group functional
  */
 public function testCount()
 {
     $index = $this->_createIndex();
     $search = new Search($index->getClient());
     $type = $index->getType('test');
     $doc = new Document(1, array('id' => 1, 'username' => 'ruflin'));
     $type->addDocument($doc);
     $index->refresh();
     $search->addIndex($index);
     $search->addType($type);
     $result1 = $search->count(new \Elastica\Query\MatchAll());
     $this->assertEquals(1, $result1);
     $result2 = $search->count(new \Elastica\Query\MatchAll(), true);
     $this->assertInstanceOf('\\Elastica\\ResultSet', $result2);
     $this->assertEquals(1, $result2->getTotalHits());
 }
Example #3
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function getItemCount()
 {
     return $this->search->count();
 }
Example #4
0
 /**
  * Invoke Elasticsearch count.
  *
  * @param Query  $query
  * @param string $index
  * @param string $type
  * @param array  $options
  *
  * @return \Elastica\ResultSet
  */
 public function count($query, $type, $index = 'activehire', $options = [])
 {
     $search = new Search($this->client);
     $search->addType($type);
     $search->addIndex($index);
     $search->setOptions($options);
     $result = $search->count($query);
     return $result;
 }
 function getCount()
 {
     $search = new Search($this->client);
     $count = $search->count($this->query->toArray());
     return $count->count();
 }
Example #6
0
 public function testCountRequest()
 {
     $client = $this->_getClient();
     $search = new Search($client);
     $index = $client->getIndex('zero');
     $index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true);
     $docs = array();
     $docs[] = new Document(1, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $docs[] = new Document(2, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $docs[] = new Document(3, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $docs[] = new Document(4, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $docs[] = new Document(5, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $docs[] = new Document(6, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $docs[] = new Document(7, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $docs[] = new Document(8, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $docs[] = new Document(9, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $docs[] = new Document(10, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $docs[] = new Document(11, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'farrelley'));
     $type = $index->getType('zeroType');
     $type->addDocuments($docs);
     $index->refresh();
     $search->addIndex($index)->addType($type);
     $count = $search->count('farrelley');
     $this->assertEquals(11, $count);
 }
 public function searchAction()
 {
     //WIP, todo: export to repository and use it in Search Playlists
     $elasticaClient = new Client();
     $playListIndex = $elasticaClient->getIndex('playlist');
     $trackType = $playListIndex->getType('track');
     $search = new Search($elasticaClient);
     $search->addIndex($playListIndex)->addType($trackType);
     $query = new Query();
     $query->setSize(5)->setSort(['name' => 'asc'])->setFields(['name', 'ids', 'id', 'composer'])->setExplain(true)->setVersion(true)->setHighlight(['fields' => 'composer']);
     $query->setQuery(new MatchAll());
     //        $query->addAggregation(new \Elastica\Aggregation\Range('name'));
     //        $term = new \Elastica\Suggest\Term('name', 'field');
     //        $term->setText('aaaaa');
     //        $query->setSuggest(new \Elastica\Suggest($term));
     //        $query->setFacets([new \Elastica\Facet\Range('name')]);
     $search->setQuery($query);
     $resultSet = $search->search();
     $numberOfEntries = $search->count();
     $results = $resultSet->getResults();
     $totalResults = $resultSet->getTotalHits();
     return $this->render('PlayWithElasticSearchBundle:Elastica:search.html.twig', ['query' => $query, 'numberOfEntries' => $numberOfEntries, 'resultSet' => $resultSet, 'results' => $results, 'totalResults' => $totalResults]);
 }