Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination throws error Undefined array key "totalHits" #895

Open
vwmoose opened this issue Dec 11, 2024 · 1 comment
Open

Pagination throws error Undefined array key "totalHits" #895

vwmoose opened this issue Dec 11, 2024 · 1 comment

Comments

@vwmoose
Copy link

vwmoose commented Dec 11, 2024

Scout Version

10.11

Scout Driver

Meilisearch

Laravel Version

11.31

PHP Version

8.2

Database Driver & Version

MySQL 8.0.32

SDK Version

meilisearch/meilisearch-php v1.11

Meilisearch CLI Version

No response

Description

When performing a meilisearch query using ->get() everything works fine, I get back the default 20 rows and the totalHits is returned and correct.

As soon as I replace ->get() with ->paginate(20) it throws the error Undefined array key "totalHits" as the key is missing from the meilisearch $results passed to MeilisearchEngine.php getTotalCount() method.

If I alter the getTotalCount() method to return $results['totalHits'] ?? $results['nbHits'] I get paginated results as expected but only for one page even though $results['nbHits'] equals 1000.

Here is my code in the controller:

$filters = [ "filter" => "price.amount >= 100 AND price.amount <= 200" ];`

$results = Property::search($search, function(Indexes $meilisearch, $query, $options) use ($filters) {
return $meilisearch->search($query, $filters);
})
->query(fn (Builder $query) => $query->withCount(['images']))
->paginate(20);

The above code only works with my hack.

Steps To Reproduce

As above.

Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants