/** * {@inheritdoc} */ public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) { if ($state && $state->isActive()) { $filter = new RangeFilter($this->getField(), $state->getValue()); $search->addPostFilter($filter); } }
/** * {@inheritdoc} */ public function preProcessSearch(Search $search, Search $relatedSearch, FilterState $state = null) { $name = $state ? $state->getName() : $this->getField(); $agg = new TermsAggregation($name); $agg->setField($this->getField()); $search->addAggregation($agg); }
/** * {@inheritdoc} */ public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) { if ($state && $state->isActive()) { $search->setFrom($this->countPerPage * ($state->getValue() - 1)); } $search->setSize($this->countPerPage); }
/** * {@inheritdoc} */ public function getState(Request $request) { $state = new FilterState(); $value = $request->get($this->getRequestField()); if (isset($value) && $value !== '') { $value = is_array($value) ? array_values($value) : $value; $state->setActive(true); $state->setValue($value); $state->setUrlParameters([$this->getRequestField() => $value]); } return $state; }
/** * {@inheritdoc} */ public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) { if ($state && $state->isActive()) { if (strpos($this->getField(), ',') !== false) { $subQuery = new BoolQuery(); foreach (explode(',', $this->getField()) as $field) { $subQuery->add(new FuzzyQuery($field, $state->getValue(), $this->getParameters()), 'should'); } $search->addQuery($subQuery, 'must'); } else { $search->addQuery(new FuzzyQuery($this->getField(), $state->getValue(), $this->getParameters()), 'must'); } } }
/** * {@inheritdoc} */ public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) { if ($state && $state->isActive()) { $stateValue = $state->getValue(); if (!empty($this->choices[$stateValue]['fields'])) { foreach ($this->choices[$stateValue]['fields'] as $sortField) { $search->addSort(new EsSort($sortField['field'], $sortField['order'], null, $sortField['mode'])); } } else { $sortField = $this->choices[$stateValue]; $search->addSort(new EsSort($sortField['field'], $sortField['order'], null, $sortField['mode'])); } } else { foreach ($this->choices as $choice) { if ($choice['default']) { $search->addSort(new EsSort($choice['field'], $choice['order'])); break; } } } }
/** * {@inheritdoc} */ public function preProcessSearch(Search $search, Search $relatedSearch, FilterState $state = null) { $name = $state ? $state->getName() : $this->getField(); $aggregation = new TermsAggregation($name); $aggregation->setField($this->getField()); if ($this->getSortType()) { $aggregation->addParameter('order', [$this->getSortType()['type'] => $this->getSortType()['order']]); } $aggregation->addParameter('size', 0); if ($this->getSize() > 0) { $aggregation->addParameter('size', $this->getSize()); } if ($relatedSearch->getPostFilters()) { $filterAggregation = new FilterAggregation($name . '-filter'); $filterAggregation->setFilter($relatedSearch->getPostFilters()); $filterAggregation->addAggregation($aggregation); $search->addAggregation($filterAggregation); } else { $search->addAggregation($aggregation); } }
/** * {@inheritdoc} */ public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) { if ($state && $state->isActive()) { $search->addPostFilter(new TermsFilter($this->getField(), $state->getValue(), ['execution' => 'and']), 'must_not'); } }