コード例 #1
0
 /**
  * {@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);
     }
 }
コード例 #2
0
 /**
  * {@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);
 }
コード例 #3
0
ファイル: Pager.php プロジェクト: vinhdrt/FilterManagerBundle
 /**
  * {@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);
 }
コード例 #4
0
 /**
  * {@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;
 }
コード例 #5
0
 /**
  * {@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');
         }
     }
 }
コード例 #6
0
ファイル: Sort.php プロジェクト: vinhdrt/FilterManagerBundle
 /**
  * {@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;
             }
         }
     }
 }
コード例 #7
0
 /**
  * {@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);
     }
 }
コード例 #8
0
 /**
  * {@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');
     }
 }