Пример #1
0
 /**
  * @inheritdoc
  */
 public function addFacet(FacetInterface $facet)
 {
     $this->_facets[$facet->getName()] = $facet;
     $options = ['field' => $facet->getField()];
     if ($facet instanceof RangeFacetInterface) {
         $options = array_merge($options, $this->getRangeAggregationOptions($facet));
         if (!empty($options['ranges'])) {
             $this->addAggregation($facet->getName(), 'range', $options);
         }
     } elseif ($facet instanceof IntervalFacetInterface) {
         $options = array_merge($options, $this->getIntervalAggregationOptions($facet));
         $this->addAggregation($facet->getName(), 'histogram', $options);
     } else {
         $options = array_merge($options, $this->getTermsAggregationOptions($facet));
         $this->addAggregation($facet->getName(), 'terms', $options);
     }
     return $this;
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function addFacet(FacetInterface $facet)
 {
     $this->_facets[$facet->getName()] = $facet;
     return $this;
 }
Пример #3
0
 /**
  * @param FacetInterface $facet
  * @return array
  */
 protected function getAggregationConfig(FacetInterface $facet)
 {
     $aggregation = [];
     $options = ['field' => $facet->getField()];
     $values = $facet->getValues();
     if ($values) {
         $valuesByType = [];
         foreach ($values as $value) {
             $valuesByType[Inflector::camel2id((new ReflectionClass($value))->getShortName(), '_')][] = $value;
         }
         foreach ($valuesByType as $type => $values) {
             $value = $values[0];
             if ($value instanceof RangeFacetValueInterface) {
                 $aggregationOptions = $this->getRangeAggregationOptions($values);
                 $aggregationType = 'range';
             } else {
                 $aggregationOptions = $this->getTermsAggregationOptions($values);
                 $aggregationType = 'terms';
             }
             $aggregation[] = ['name' => $facet->getName() . '_' . $type, 'type' => $aggregationType, 'options' => array_merge($options, $aggregationOptions)];
         }
     } elseif ($facet instanceof IntervalFacetInterface) {
         $aggregation = ['name' => $facet->getName(), 'type' => 'histogram', 'options' => array_merge($options, $this->getIntervalAggregationOptions($facet))];
     } else {
         $aggregation = ['name' => $facet->getName(), 'type' => 'terms', 'options' => array_merge($options, $this->getTermsAggregationOptions())];
     }
     return $aggregation;
 }