Monday, April 10, 2017

Laravel Scout and Algolia Pagination Troubles

I am having trouble with pagination in Laravel 5.4. I am using Scout and algolia as the 'driver'. The data I am paginating is from algolia via a submission from a form search and everything seems to work - until I hit a result with over 34 pages. The first 34 pages seem to work just fine as far as I can tell, but after page 34 things seem to go south. I'm new to Laravel and I love the idea of not having to program pagination from scratch, but why is this happening?


Page 1 results:

Looks good and everything seems to work

Page 1 die and dump


Page 34 results:

Still working...

Page 34 die and dump


Page 35 and beyond:

Everything after 34 shows 0 results...

Page 35 die and dump returns 0


Here I have a function in my controller that handles the search:

  public function search(Request $request)

    {

      $object = $request->input('query');

      $results = Item::search($object)->paginate(30);
      dd($results);

    }


Next I have the model:
namespace App;

use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;

class Item extends Model
{
    use Searchable;
}


Interesting fact

What I have noticed is that if I change paginate(30) to paginate(20), the maximum page I can reach before things fail is page 50.



via noreason

Advertisement