nqxcode / laravel-lucene-search

Laravel 4.2, 5.* package for full-text search over Eloquent models based on ZF2 Lucene.
73 stars 28 forks source link

Pagination #35

Closed mostafaznv closed 7 years ago

mostafaznv commented 8 years ago

hi ... thanks for your nice package... it works fine ... but i think it's better to use LengthAwarePaginator instead Paginator LengthAwarePaginator shows a full pagination and i think if we have many pages, it's better to show a full pagination...

i changed it in your package, but if you publish new version, all of my modifications gone ... please change that, i think it's more practical...

dxrrxns commented 8 years ago

100% what @mostafaznv said... I had to do the same so that I could use multi-page and total count

GimmyBreaker commented 7 years ago

Well, it is not so hard to implement by yourself. I don't know if there was some changes, but in Laravel 5.2.45 there is no way to Pagintor work correctly because of mismatch in parameters: public function __construct($items, $perPage, $currentPage = null, array $options = [])

Find in namespace Nqxcode\LuceneSearch\Query class Builder, you have there paginate function. Original code should be:

$page = $page ?: request()->input('page', 1);

$this->limit($perPage, ($page - 1) * $perPage);
$models = $this->get()->all();

$total = $this->count();

$paginator = new Paginator($models, $total, $perPage);

return $paginator;

You just need to change $paginator = new Paginator($models, $total, $perPage); to $paginator = new \Illuminate\Pagination\LengthAwarePaginator($models, $total, $perPage, $page); and that's it.

nqxcode commented 7 years ago

Pagination fixed.