Apply search items to the query.

@param Builder $query
@param array   $search

@return void
550907
private static function applySearch(&$query, $search)
    {
        foreach ($search as $name => $filters) {
            foreach ($filters as $filter) {
                self::applySearchFilter($query, $filter);
            }
        }
    }
1053786
protected function performJoin(Builder $query = null)
    {
        $query = $query ?: $this->query;

        $ownerKey = $this->getQualifiedOwnerKeyName();

        $query->join($this->throughChild->getTable(), $ownerKey , '=', $this->getQualifiedFirstKeyName());
        $query->select([
            '*' => $this->related->qualifyColumn('*'),
            $this->secondKey => $this->throughChild->getQualifiedKeyName().' as '.$this->secondKey
        ]);

        if ($this->throughChildSoftDeletes()) {
            $query->whereNull($this->throughChild->getQualifiedDeletedAtColumn());
        }
    }
1300585
protected function applySearchVariants(SearchQuery $query)
    {
        $classes = count($query->classes) ? $query->classes : $this->getClasses();

        /** @var SearchVariant_Caller $variantCaller */
        $variantCaller = SearchVariant::withCommon($classes);
        $variantCaller->call('alterQuery', $query, $this);
    }
26228
public function apply($builder, QueryInterface $query): void
    {
        // Apply joins
        foreach ($query->getJoins() as $join) {
            if ($join->isInner()) {
                $builder->innerJoin($join->getFromAlias(), $join->getTo(), $join->getToAlias(), $join->getCondition());
            } else {
                $builder->leftJoin($join->getFromAlias(), $join->getTo(), $join->getToAlias(), $join->getCondition());
            }
        }

        // Apply rules
        foreach ($query->getRules() as $rule) {
            $builder->andWhere($rule->getRule());
        }

        // Apply parameters
        foreach ($query->getParameters() as $parameter) {
            $builder->setParameter($parameter->getName(), $parameter->getValue(), $parameter->getType());
        }

        // Apply orders
        foreach ($query->getOrders() as $order) {
            $builder->addOrderBy($order->getField(), $order->getDirection());
        }
    }
1224438
public function runQueryFilter(\Illuminate\Database\Query\Builder &$query)
    {
        if ($filter = $this->getOption('query_filter')) {
            $filter($query);
        }
    }
151132
public function buildQuery(Builder $query = null): Builder
    {
        $query = $this->getSubQuery($this->meta, $query, $this->conditions['rules'], $this->conditions['condition']);

        if ($this->offset > 0) {
            $query->offset($this->offset);
        }
        if ($this->limit > 0) {
            $query->limit($this->limit);
        }

        return $query;
    }
1026663
public function apply(Builder $query, string $tableAlias = null, string $customName = null)
    {
        if ($this->hasBeenApplied()) {
            return;
        }

        $name = $this->buildDbName($tableAlias, $customName);

        $query->orderBy($name, $this->direction);
        $this->setApplied(true);
    }
1212851
public function search(array $search)
        {
            $results    = array();
            $cart       = $this->getContent();
            $rows       = $cart->_fields;
            foreach($rows as $rowId) {
                $item  = $cart->$rowId;
                $found = $item->search($search);

                if(true === $found) {
                    $results[] = $item;
                }
            }

            return (empty($results)) ? false : $results;
        }
17359
public void search(String query) {
        final Query newQuery = searcher.getQuery().setQuery(query);
        searcher.setQuery(newQuery).search();
    }
1044372
public function search($query) {
        $result = array();
        foreach ($this->get_children() as $child) {
            $subsearch = $child->search($query);
            if (!is_array($subsearch)) {
                debugging('Incorrect search result from '.$child->name);
                continue;
            }
            $result = array_merge($result, $subsearch);
        }
        return $result;
    }
575563
protected function prefixWheres(Builder $query, $prefix)
    {
        if (is_array($query->getQuery()->wheres))
        {
            $query->getQuery()->wheres = array_map(function($where) use($prefix)
            {
                $column = $where['column'];
                $where['column'] = ($this->isId($column)) ? $column : $prefix .'.'. $column;
                return $where;
            }, $query->getQuery()->wheres);
        }
    }
1020915
protected function validate($query)
    {
        if ($this->client->getIndex() == null) {
            throw new SearchException("Index cannot be null");
        }
        if ($this->client->getType() == null) {
            throw new SearchException("Type cannot be null");
        }
        if ($query == null) {
            throw new SearchException("Query can't be null");
        }
    }
1114054
protected function setKeysForSaveQuery(Builder $query)
    {
        foreach ($this->getKeyName() as $key) {
            if (isset($this->$key))
                $query->where($key, '=', $this->$key);
            else
                throw new Exception(__METHOD__ . 'Missing part of the primary key: ' . $key);
        }

        return $query;
    }
1042739
protected function addSelectsToQuery(Builder $query, array $selects)
    {
        if (!empty($selects)) {
            $query->selectRaw('max(' . implode(' + ', $selects) . ') as relevance', $this->searchBindings);
        }
    }
795052
public function applyToQuery(Builder $query)
    {
        $this->query = $query;

        foreach ($this->request->all() as $filter => $value) {
            $method = Str::camel($filter);

            if ($this->filterCanBeApplied($method, $value)) {
                call_user_func([$this, $method], $value);
            }
        }

        return $query;
    }
454395
public function applyAll(Builder $query)
    {
        foreach($this->units as $unit)
        {
            $unit->apply($query);
        }
    }
938094
private function whereInitialNorwegian(Builder $query, Expression $field, string $letter): void
    {
        switch ($letter) {
            case 'A':
                $query->where($field, 'LIKE', 'A%')->where($field, 'NOT LIKE', 'AA%');
                break;

            case 'Å':
                $query->where(static function (Builder $query) use ($field): void {
                    $query
                        ->where($field, 'LIKE', 'Å%')
                        ->orWhere($field, 'LIKE', 'AA%');
                });
                break;

            default:
                $query->where($field, 'LIKE', '\\' . $letter . '%');
                break;
        }
    }