Elastica\Search::count PHP Méthode

count() public méthode

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
Résultat integer | ResultSet
    public function count($query = '', $fullResult = false)
    {
        $this->setOptionsAndQuery(null, $query);
        $query = $this->getQuery();
        $query->setSize(0);
        $path = $this->getPath();
        $response = $this->getClient()->request($path, Request::GET, $query->toArray(), [self::OPTION_SEARCH_TYPE => self::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH]);
        $resultSet = $this->_builder->buildResultSet($response, $query);
        return $fullResult ? $resultSet : $resultSet->getTotalHits();
    }

Usage Example

 /**
  * 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);
 }
All Usage Examples Of Elastica\Search::count