/** * and filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-and-filter.html * @param AbstractFilter[] $filters * @return BoolAnd */ public function bool_and(array $filters) { $and = new BoolAnd(); $and->setFilters($filters); return $and; }
private static function newAnd() { $and = new BoolAnd(); $and->setFilters(func_get_args()); return $and; }
/** * getFilter * * @access private * @return AbstractFilter */ private function getFilter() { if (!$this->filterList) { return null; } if (count($this->filterList) == 1) { return current($this->filterList); } $boolFilters = []; $andFilters = []; foreach ($this->filterList as $tmpFilter) { if ($this->isAndFilter($tmpFilter)) { $andFilters[] = $tmpFilter; } else { $boolFilters[] = $tmpFilter; } } $boolFilter = null; $nbBoolFilters = count($boolFilters); if ($nbBoolFilters > 1) { $boolFilter = new Filter\Bool(); foreach ($boolFilters as $tmpFilter) { $boolFilter->addMust($tmpFilter); } array_unshift($andFilters, $boolFilter); } elseif ($nbBoolFilters == 1) { $andFilters = array_merge($boolFilters, $andFilters); } $nbAndFilters = count($andFilters); if ($nbAndFilters == 1) { return current($andFilters); } elseif ($nbAndFilters > 1) { $filter = new Filter\BoolAnd(); $filter->setFilters($andFilters); return $filter; } return null; }