Skip to content

Incorrect Total Count in Laravel Scout Pagination #819

@raz-iacob

Description

@raz-iacob

Scout Version

10.8.5

Scout Driver

Typesense

Laravel Version

11.2

PHP Version

8.3.3

Database Driver & Version

No response

SDK Version

No response

Meilisearch CLI Version

No response

Description

When using Laravel Scout for searching with pagination, I'm encountering an issue where the total count of records returned by the pagination (paginate(200)) method is equal to the number of items per page specified (200), instead of reflecting the actual total number of matching records.

Steps To Reproduce

  1. I executed the following Scout search query with pagination:
    dd(ImportedProperty::search('pipera')
        ->query(fn (Builder $query) => $query->with(['imported_district']))
        ->paginate(200)->onEachSide(1)->withQueryString()
        ->through(fn ($obj) => [
            'name' => $obj->source_id,
            'district' => $obj->imported_district?->name ?? '',
        ]));
    

Observe that the LengthAwarePaginator returned indicates a total of 200 records, regardless of the actual total count of matching records. When I changed it to 10 per page I got a total of 10 records found.

Expected Behavior:
The total count ($searchResults->total()) returned by Laravel Scout's pagination should accurately reflect the complete number of records that match the search criteria ('pipera'), independent of the pagination settings.

Actual Behavior:
The total count ($searchResults->total()) is consistently equal to the number of items per page specified in paginate(200), leading to an incorrect representation of the total number of matching records.

Output of dd() showing the LengthAwarePaginator and its properties.

Screenshot 2024-04-08 at 1 39 14 PM

Currently, there is no workaround as the issue seems to be related to the pagination behavior within Laravel Scout.

Please advise on how to resolve this issue or if any additional information is required to further investigate.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions