/**
  * Return field faceted data from faceted search result
  *
  * @param string $field
  * @return array
  * @throws StateException
  */
 public function getFacetedData($field)
 {
     $this->_renderFilters();
     $result = [];
     $aggregations = $this->searchResult->getAggregations();
     $bucket = $aggregations->getBucket($field . '_bucket');
     if ($bucket) {
         foreach ($bucket->getValues() as $value) {
             $metrics = $value->getMetrics();
             $result[$metrics['value']] = $metrics;
         }
     } else {
         throw new StateException(__('Bucket do not exists'));
     }
     return $result;
 }
예제 #2
0
 /**
  * Return field faceted data from faceted search result
  *
  * @param string $field
  * @return array
  * @throws StateException
  */
 public function getFacetedData($field)
 {
     $this->_renderFilters();
     $result = [];
     $aggregations = $this->searchResult->getAggregations();
     // This behavior is for case with empty object when we got EmptyRequestDataException
     if (null !== $aggregations) {
         $bucket = $aggregations->getBucket($field . RequestGenerator::BUCKET_SUFFIX);
         if ($bucket) {
             foreach ($bucket->getValues() as $value) {
                 $metrics = $value->getMetrics();
                 $result[$metrics['value']] = $metrics;
             }
         } else {
             throw new StateException(__('Bucket does not exist'));
         }
     }
     return $result;
 }