/** * Creates the full facet definition, which includes the basic * facet definition of the parent. * * @see \Elastica\Facet\AbstractFacet::toArray() * * @throws \Elastica\Exception\InvalidException When the right fields haven't been set. * * @return array */ public function toArray() { /* * Check the facet for validity. * There are three ways to set the key and value field for the range: * - a single field for both key and value; or * - separate fields for key and value; or * - separate scripts for key and value. */ $fieldTypesSet = 0; if (isset($this->_params['field'])) { $fieldTypesSet++; } if (isset($this->_params['key_field'])) { $fieldTypesSet++; } if (isset($this->_params['key_script'])) { $fieldTypesSet++; } if ($fieldTypesSet === 0) { throw new InvalidException('Neither field, key_field nor key_script is set.'); } elseif ($fieldTypesSet > 1) { throw new InvalidException('Either field, key_field and key_value or key_script and value_script should be set.'); } /* * Set the range in the abstract as param. */ $this->_setFacetParam('range', $this->_params); return parent::toArray(); }
/** * Adds a Facet to the query * * @param \Elastica\Facet\AbstractFacet $facet Facet object * @return \Elastica\Query Query object */ public function addFacet(AbstractFacet $facet) { $this->_params['facets'][$facet->getName()] = $facet->toArray(); return $this; }
/** * Creates the full facet definition, which includes the basic * facet definition of the parent. * * @see \Elastica\Facet\AbstractFacet::toArray() * * @return array */ public function toArray() { $this->_setFacetParam('terms', $this->_params); return parent::toArray(); }
/** * Creates the full facet definition, which includes the basic * facet definition of the parent. * * @see \Elastica\Facet\AbstractFacet::toArray() * * @return array */ public function toArray() { $this->_setFacetParam('terms', $this->_params); $array = parent::toArray(); $baseName = $this->_getBaseName(); if (isset($array[$baseName]['script'])) { $array[$baseName]['script'] = $array[$baseName]['script']['script']; } return $array; }