<commit_before><?php
/**
 * Created by PhpStorm.
 * User: bmix
 * Date: 5/12/17
 * Time: 12:05 PM
 */

namespace ElasticScout;

use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Database\Eloquent\Collection;

/**
 * Class Builder
 * @package ElasticScout
 */
class Builder extends \Laravel\Scout\Builder
{
    /**
     * holds the raw query language
     *
     * @var array
     */
    protected $dsl = [];

    /**
     * holds raw query aggregations
     * @var array
     */
    protected $aggregations = [];

    /**
     * holds raw post filters
     * @var array
     */
    protected $post_filter = [];

    /**
     * holds raw highlights
     * @var array
     */
    protected $highlights = [];

    /**
     * the specified combo query
     *
     * @var string
     */
    protected $combo = '';

    /**
     * execute query and paginate results
     *
     * @param null $perPage
     * @param string $pageName
     * @param null $page
     * @return LengthAwarePaginator
     */
    public function paginate($perPage = null, $pageName = 'page', $page = null)
    {
        $engine = $this->engine();

        $page = $page ?: Paginator::resolveCurrentPage($pageName);

        $perPage = $perPage ?: $this->model->getPerPage();

        $results = Collection::make($engine->map(
            $rawResults = $engine->paginate($this, $perPage, $page), $this->model

        ));

        $paginator = (new LengthAwarePaginator($results, $engine->getTotalCount($rawResults), $perPage, $page, [
            'path' => Paginator::resolveCurrentPath(),
            'pageName' => $pageName,
        ]));

        return $paginator->appends('query', $this->query);
    }

    /**
     * Add an "order" for the search query.
     *
     * @param  string  $column
     * @param  mixed  $direction
     * @return $this<commit_msg>appended common get vars (query, q, filter, f) to pagination object<commit_after><?php
/**
 * Created by PhpStorm.
 * User: bmix
 * Date: 5/12/17
 * Time: 12:05 PM
 */

namespace ElasticScout;

use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Database\Eloquent\Collection;

/**
 * Class Builder
 * @package ElasticScout
 */
class Builder extends \Laravel\Scout\Builder
{
    /**
     * holds the raw query language
     *
     * @var array
     */
    protected $dsl = [];

    /**
     * holds raw query aggregations
     * @var array
     */
    protected $aggregations = [];

    /**
     * holds raw post filters
     * @var array
     */
    protected $post_filter = [];

    /**
     * holds raw highlights
     * @var array
     */
    protected $highlights = [];

    /**
     * the specified combo query
     *
     * @var string
     */
    protected $combo = '';

    /**
     * execute query and paginate results
     *
     * @param null $perPage
     * @param string $pageName
     * @param null $page
     * @return LengthAwarePaginator
     */
    public function paginate($perPage = null, $pageName = 'page', $page = null)
    {
        $engine = $this->engine();

        $page = $page ?: Paginator::resolveCurrentPage($pageName);

        $perPage = $perPage ?: $this->model->getPerPage();

        $results = Collection::make($engine->map(
            $rawResults = $engine->paginate($this, $perPage, $page), $this->model

        ));

        $paginator = (new LengthAwarePaginator($results, $engine->getTotalCount($rawResults), $perPage, $page, [
            'path' => Paginator::resolveCurrentPath(),
            'pageName' => $pageName,
        ]));

        //we append either $this->query, request('query'), or request('q') if set
        if(!empty($this->query)) {

            $paginator->appends('query',$this->query);

        } elseif (request()->has('query')) {

            $paginator->appends('query',request('query'));

        } elseif (request()->has('q')) {

            $paginator->appends('q',request('q'));

        }

        //we append either request('filter') or request('f') if set
        if(request()->has('filter')) {
            $paginator->appends('filter',request('filter'));
        } elseif (request()->has('f')) {
            $paginator->appends('f',request('f'));
        }

        return $paginator;
    }

    /**
     * Add an "order" for the search query.
     *
     * @param  string  $column
     * @param  mixed  $direction
     * @return $this
{'fraction_non_alphanumeric': 0.15315315315315314, 'fraction_numerical': 0.004054054054054054, 'mean_word_length': 2.255865102639296, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5167888', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1339, 'n_words': 306}