Perform the given search on the engine.

@param Builder $builder

@return mixed
346005
public function search(Builder $builder)
    {
        $result = [];

        if ($this->shouldNotRun($builder)) {
            $result['results'] = Collection::make();
            $result['count'] = 0;

            return $result;
        }

        $mode = $this->shouldUseFallback($builder) ? $this->fallbackMode : $this->mode;

        $whereRawString = $mode->buildWhereRawString($builder);
        $params = $mode->buildParams($builder);

        $model = $builder->model;
        $query = $model::whereRaw($whereRawString, $params);

        if($builder->callback){
            $query = call_user_func($builder->callback, $query, $this);
        }

        $result['count'] = $query->count();

        if (property_exists($builder, 'orders') && !empty($builder->orders)) {
            foreach ($builder->orders as $order) {
                $query->orderBy($order['column'], $order['direction']);
            }
        }

        if ($builder->limit) {
            $query = $query->take($builder->limit);
        }

        if (property_exists($builder, 'offset') && $builder->offset) {
            $query = $query->skip($builder->offset);
        }

        $result['results'] = $query->get();

        return $result;
    }
108728
public static function builder($builder = null)
    {
        if (is_object($builder)) {
            self::$builder = $builder;
        }

        return isset(self::$builder) ? self::$builder : self::$builder = new Builder;
    }
115105
public function paginate(Builder $builder, $perPage, $page)
    {
        return $this->performSearch($builder, [
            'numericFilters' => $this->filters($builder),
            'hitsPerPage' => $perPage,
            'page' => $page - 1,
        ]);
    }
535966
public static function of($builder)
    {
        if ($builder instanceof \Illuminate\Database\Eloquent\Builder) {
            $builder = $builder->getQuery();
        }

        $collection = new Collection($builder);
        $collection = self::_addCustomAttributes($collection);
        self::$_lastCollection = $collection;
        return self::collection();
    }
1232140
public function query() : Builder
	{
		if (trim($conditions = $this->conditions) !== '') {
			$this->builder->where('condition', 'LIKE', $conditions);
		}

		return $this->builder;
	}
164728
public function query() : Builder
	{
		if (trim($brand = $this->brand) !== '') {
			$this->builder->where('brand', 'LIKE', $brand);
		}

		return $this->builder;
	}
743496
protected function createCountBuilderFromBuilder(QueryBuilder $builder): ModelQueryBuilder
    {
        $countBuilder = $this->createBuilder($this->getModelClass());
        $countBuilder->setParameters($builder->getParameters());
        $countBuilder->select('COUNT(*)')->from('(' . $builder->getSQL() . ') AS RESULT');

        return $countBuilder;
    }
1148431
protected function addRejected(Builder $builder)
    {
        $builder->macro('rejected', function (Builder $builder) {
            $model = $builder->getModel();

            $this->remove($builder, $model);

            $builder->where($model->getQualifiedStatusColumn(), '=', Status::REJECTED);

            return $builder;
        });
    }
1280459
protected function filters(Builder $builder)
    {
        return collect($builder->wheres)->map(function ($value, $key) {
            return ['match_phrase' => [$key => $value]];
        })->values()->all();
    }
869827
public function remove(Builder $builder)
    {
        $column = $builder->getModel()->getQualifiedDeletedAtColumn();

        $query = $builder->getQuery();

        foreach ((array) $query->wheres as $key => $where) {
            if ($this->isSoftDeleteConstraint($where, $column)) {
                unset($query->wheres[$key]);

                $query->wheres = array_values($query->wheres);
            }
        }
    }
686285
public function setQueryBuilder(\pwf\components\querybuilder\interfaces\SelectBuilder $builder)
    {
        $this->queryBuilder = $builder;
        return $this;
    }
452993
public function compile(Builder $builder)
    {
        $ands = $builder->filters['and'];
        $ors = $builder->filters['or'];
        $raws = $builder->filters['raw'];

        $query = $this->concatenate($raws);

        $query = $this->compileWheres($ands, $query);

        $query = $this->compileOrWheres($ors, $query);

        // We need to check if the query is already nested, otherwise
        // we'll nest it here and return the result.
        if (! $builder->isNested()) {
            $total = count($ands) + count($raws);

            // Make sure we wrap the query in an 'and' if using
            // multiple filters. We also need to check if only
            // one where is used with multiple orWheres, that
            // we wrap it in an `and` query.
            if ($total > 1 || (count($ands) === 1 && count($ors) > 0)) {
                $query = $this->compileAnd($query);
            }
        }

        return $query;
    }
845003
protected function performSearch(Builder $builder, $perPage = 0, $page = 1)
    {
        // We have to preserve the model in order to allow for
        // correct behavior of mapIds() method which currently
        // does not receive a model instance
        $this->preserveModel($builder->model);

        $indexColumn = $this->getIndexColumn($builder->model);

        // Build the SQL query
        $query = $this->database
            ->table($builder->index ?: $builder->model->searchableAs())
            ->select($builder->model->getKeyName())
            ->selectRaw("{$this->rankingExpression($builder->model, $indexColumn)} AS rank")
            ->selectRaw('COUNT(*) OVER () AS total_count')
            ->whereRaw("$indexColumn @@ \"tsquery\"");

        // Apply where clauses that were set on the builder instance if any
        foreach ($builder->wheres as $key => $value) {
            $query->where($key, $value);
        }

        // If parsed documents are being stored in the model's table
        if (! $this->isExternalIndex($builder->model)) {
            // and the model uses soft deletes we need to exclude trashed rows
            if ($this->usesSoftDeletes($builder->model)) {
                $query->whereNull($builder->model->getDeletedAtColumn());
            }
        }

        // Apply order by clauses that were set on the builder instance if any
        foreach ($builder->orders as $order) {
            $query->orderBy($order['column'], $order['direction']);
        }

        // Apply default order by clauses (rank and id)
        if (empty($builder->orders)) {
            $query->orderBy('rank', 'desc')
                ->orderBy($builder->model->getKeyName());
        }

        if ($perPage > 0) {
            $query->skip(($page - 1) * $perPage)
                ->limit($perPage);
        }

        // The choices of parser, dictionaries and which types of tokens to index are determined
        // by the selected text search configuration which can be set globally in config/scout.php
        // file or individually for each model in searchableOptions()
        // See https://www.postgresql.org/docs/current/static/textsearch-controls.html
        $tsQuery = $builder->callback
            ? call_user_func($builder->callback, $builder, $this->searchConfig($builder->model), $query)
            : $this->defaultQueryMethod($builder->query, $this->searchConfig($builder->model));

        $query->crossJoin($this->database->raw($tsQuery->sql().' AS "tsquery"'));
        // Add TS bindings to the query
        $query->addBinding($tsQuery->bindings(), 'join');

        return $this->database
            ->select($query->toSql(), $query->getBindings());
    }
1198155
public function index($builder = null)
    {
        $models = $this->repository->all([], true);

        return response()->json($models, 200);
    }
339242
public function apply(Builder $builder)
    {
        $model = $builder->getModel();

        $builder->whereNull($model->getQualifiedDeletedAtColumn());

        $this->extend($builder);
    }
1184967
public function apply($builder)
    {
        if (!empty($values = $this->getValues())) {
            $range = json_decode($values, true);
            if (!isset($range['start']) or ! isset($range['end'])) {
                return $builder;
            }
            $start = $range['start'] . ' 00:00:00';
            $end   = $range['end'] . ' 23:59:59';
            $builder->whereBetween('tbl_notifications_stack.created_at', [$start, $end]);
        }
    }
1306717
public function applyTo(ReportBuilder $builder)
    {
        $this->basic->applyTo($builder);
        $this->report->applyTo($builder);

        return $builder;
    }