Open
Description
Description
It seems the TypesenseEngine doesn't correctly work with Scout's ->paginate
, particularly when results exceeed 250 hits, as the total in the pagination gets set to the default perPage
for some reason. It seems the MeiliSearch adapter also had this issue, see: laravel/scout#535
The workaround I have is to implement the pagination manually with:
$searchData = $query->query(fn ($search) => $search->with($relations))->get();
$paginatedSearchResults = new LengthAwarePaginator($searchData, $query->raw()['found'], $perPage);
Steps to reproduce
- Have a collection that exceeds 250 documents.
- Search against that collection utilising Scout and Typesense of course.
- Attempt to paginate that data with a query callback, for example with:
$query->query(fn ($search) => $search->with($relations))
->paginate($perPage)
->withQueryString();
Expected Behavior
Return a LengthAwarePaginator with 1278 total items.
Actual Behavior
Returns a LengthAwarePaginator with 15 total items.
Metadata
Typsense Version: v5.1.0-rc1
OS: MacOS 12.4 Monterey
Raw results from Typesense:
array:8 [▼
"facet_counts" => []
"found" => 1278
"hits" => array:15 [▶]
"out_of" => 171361
"page" => 1
"request_params" => array:3 [▶]
"search_cutoff" => false
"search_time_ms" => 1
]
Pagination without query callback works as expected:
Illuminate\Pagination\LengthAwarePaginator {#2096 ▼
#items: Illuminate\Database\Eloquent\Collection {#2102 ▶}
#perPage: 15
#currentPage: 1
#query: array:1 [▶]
#fragment: null
#pageName: "page"
+onEachSide: 3
#options: array:2 [▶]
#total: 1278
#lastPage: 86
}
Pagination with query callback does NOT work as expected:
Illuminate\Pagination\LengthAwarePaginator {#2431 ▼
#items: Illuminate\Database\Eloquent\Collection {#2164 ▶}
#perPage: 15
#currentPage: 1
#query: array:1 [▶]
#fragment: null
#pageName: "page"
+onEachSide: 3
#options: array:2 [▶]
#total: 15
#lastPage: 1
}
Metadata
Metadata
Assignees
Labels
No labels