Cake\ElasticSearch\Query::_buildFilter PHP Method

_buildFilter() protected method

Auxiliary function used to parse conditions into filters and store them in a _parts variable.
protected _buildFilter ( string $type, array | callable | Elastica\Filter\AbstractFilter $conditions, boolean $overwrite )
$type string The name of the part in which the filters will be stored
$conditions array | callable | Elastica\Filter\AbstractFilter The list of conditions.
$overwrite boolean Whether or not to replace previous filters.
    protected function _buildFilter($type, $conditions, $overwrite)
    {
        if ($this->_parts[$type] === null || $overwrite) {
            $this->_parts[$type] = new BoolFilter();
        }
        if ($conditions instanceof AbstractFilter) {
            $this->_parts[$type]->addMust($conditions);
            return $this;
        }
        if (is_callable($conditions)) {
            $conditions = $conditions(new FilterBuilder(), $this->_parts[$type], $this);
        }
        if ($conditions === null) {
            return $this;
        }
        if (is_array($conditions)) {
            $conditions = (new FilterBuilder())->parse($conditions);
            array_map([$this->_parts[$type], 'addMust'], $conditions);
            return $this;
        }
        $this->_parts[$type]->addMust($conditions);
        return $this;
    }