Beispiel #1
0
 /**
  * Counts results of query
  *
  * @param  string|array|Elastica_Query $query Array with all query data inside or a Elastica_Query object
  * @return int                         number of documents matching the query
  * @see Elastica_Searchable::count
  */
 public function count($query = '')
 {
     $query = Elastica_Query::create($query);
     $path = '_search';
     $response = $this->request($path, Elastica_Request::GET, $query->toArray(), array('search_type' => 'count'));
     $resultSet = new Elastica_ResultSet($response);
     return $resultSet->getTotalHits();
 }
 /**
  * Prepares query response.
  *
  * @param Elastica_ResultSet $response
  * @return array
  */
 protected function _prepareQueryResponse($response)
 {
     /* @var $response Elastica_ResultSet */
     if (!$response instanceof Elastica_ResultSet || $response->getResponse()->hasError() || !$response->count()) {
         return array();
     }
     $this->_lastNumFound = (int) $response->getTotalHits();
     $result = array();
     foreach ($response->getResults() as $doc) {
         $result[] = $this->_objectToArray($doc->getSource());
     }
     return $result;
 }