Exemple #1
0
 /**
  * Add a filter.
  *
  * If a name is given, it will be added as a key, otherwise considered as an anonymous filter
  *
  * @param AbstractFilter $filter
  * @param string         $name
  *
  * @return $this
  */
 public function addFilter(AbstractFilter $filter, $name = '')
 {
     if (empty($name)) {
         $filterArray[] = $filter->toArray();
     } else {
         $filterArray[$name] = $filter->toArray();
     }
     return $this->addParam('filters', $filterArray);
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function toArray()
 {
     $array = parent::toArray();
     if (isset($array['script'])) {
         $array['script'] = $array['script']['script'];
     }
     return $array;
 }
 /**
  * @see \Elastica\Param::toArray()
  */
 public function toArray()
 {
     $data = parent::toArray();
     $name = $this->_getBaseName();
     $filterData = $data[$name];
     if (empty($filterData)) {
         $filterData = $this->_query;
     } else {
         $filterData['query'] = $this->_query;
     }
     $data[$name] = $filterData;
     return $this->_convertArrayable($data);
 }
 /**
  *
  * Apply additional filters based on facet selection
  * @param string $module
  * @param array $options
  * @param \Elastica\Filter\AbstractFilter $moduleFilter
  */
 public function addFilters($module, array $options, \Elastica\Filter\AbstractFilter $moduleFilter)
 {
     // secFilters will only be set when a module has been selected
     if (empty($options['secFilters'])) {
         return;
     }
     $filterDefs = $options['secFilters'];
     $facetDefs = $this->loadFacetDefs($module);
     foreach ($filterDefs as $field => $values) {
         // check that we have a facet def available
         if (empty($facetDefs[$field])) {
             continue;
         }
         if ($facet = FacetFactory::get($facetDefs[$field]['type'])) {
             // set options from facet definition
             $facet->setOptions($facetDefs[$field]['options']);
             // get Elastica filter object and add it to the module filter
             if ($eFilter = $facet->getFilter($field, $values)) {
                 $moduleFilter->addMust($eFilter);
             }
         }
     }
 }
Exemple #5
0
 /**
  * Set the filter to be applied to docs in indices which do not match those specified in the "indices" parameter
  * @param  AbstractFilter $filter
  * @return Indices
  */
 public function setNoMatchFilter(AbstractFilter $filter)
 {
     return $this->setParam('no_match_filter', $filter->toArray());
 }
 /**
  * @see \Elastica\Param::toArray()
  *
  * @throws \Elastica\Exception\InvalidException
  *
  * @return array
  */
 public function toArray()
 {
     $this->setParam($this->_key, $this->_getLocationData());
     return parent::toArray();
 }
 /**
  * @param AbstractFilter $filter
  * @return \Elastica\Param
  */
 public function setFilter(AbstractFilter $filter)
 {
     return $this->setParam('filter', $filter->toArray());
 }
 /**
  * Sets query object
  *
  * @param  \Elastica\Filter\AbstractFilter $filter
  * @return \Elastica\Filter\HasParent Current object
  */
 public function setFilter($filter)
 {
     $data = $filter->toArray();
     return $this->setParam('filter', $data);
 }
 /**
  * The default source of statistical information for background term frequencies is the entire index and this scope can
  * be narrowed through the use of a background_filter to focus in on significant terms within a narrower context.
  *
  * @param AbstractFilter $filter
  *
  * @return $this
  *
  * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_custom_background_context
  */
 public function setBackgroundFilter(AbstractFilter $filter)
 {
     return $this->setParam('background_filter', $filter->toArray());
 }
 /**
  * Add a filter with a script to calculate the score
  * Only script part of script object is used
  *
  * @param  \Elastica\Filter\AbstractFilter         $filter Filter object
  * @param  \Elastica\Script|string|array           $script Script for calculating the score
  * @return \Elastica\Query\CustomFiltersScore Current object
  */
 public function addFilterScript(AbstractFilter $filter, $script)
 {
     $script = Script::create($script);
     $filterParam = array('filter' => $filter->toArray(), 'script' => $script->getScript());
     return $this->addParam('filters', $filterParam);
 }