-
Notifications
You must be signed in to change notification settings - Fork 340
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
Incorrect Total Count in Laravel Scout Pagination #824
Comments
@karakhanyans do you have any thoughts here? |
@driesvints will check this and get back with more info 👌 |
I will be happy to see this solved guys. Good luck! |
@karakhanyans any news here? |
I'll be working on this |
Hello, I encountered the same issue reported here. In my case, I was using a model with a ULID as the primary key but initially forgot to set protected $keyType = 'string'; in my model. After updating this setting, I can confirm that the pagination now works correctly. Here are the specifics of my development environment:
Apologies if this solution has already been mentioned. I hope this helps someone else experiencing the same problem. Thank you. |
Ping @jasonbosco |
@AbdullahFaqeir will be working on this going forward. |
Hi @Evenerik! Can you please dump the collection schema, and sample record in typesense and the same record in database. Below you can see a dump of my env showing a working fresh sample, I've seeded 10K users. User model settings.Search performed.Paginated search results. |
Closing this issue because it's inactive, already solved, old or not relevant anymore. Feel to open up a new issue if you're still experiencing this. |
Is it possible to reopen this because the problem persists. I tracked it down to the method getTotalCount on Builder class the $totalCount is correct but because of $this->queryCallback not being null, the total returned is the perpage number. I don't really understand what is happening after that if statment |
Could you share the information that @AbdullahFaqeir asked for here to debug this further: #824 (comment) |
I'm happy to share more information. I've notice that things stop working as they should when using a callback query indicated in the documentation here: https://laravel.com/docs/11.x/scout#customizing-the-eloquent-results-query The ecpected number of results should be 512 but they are limited to the number per page. Search performed.
Paginated search results.
I verified the total number in the Typesense Dashboard So I think the problem lies somewhere in the getTotalCount method in the Builder class Please let me know how else I can help with this. Thank you! Raz |
I don't know how I've seen the whole execution within my head to figure this out 😅 I literally didn't even go through the code. What's actually causing the issue is what happens when you apply a customisation to the query (db) which happens after the (search) query. When @razvaniacob indexed his data, he didn't index the (id) of the city, that's first. After the search results is returned normally with the correct total number count, while not just typesense, even other engines, generate a list of the plucked id's from the (search) query, using this list of id's the fetch the actual entities inside the database on order to apply the (db) query customisation on them. In this case, there was no id's being returned from the (search) query, thus, when trying to execute the (db) query customisation, it returns null because, you know! 😅. So I believe the only way for this to be fixed is to force index the models id's. |
@AbdullahFaqeir do you need anything else from me in order to finally find a fix for this problem? |
Mostly for @AbdullahFaqeir: Quick note that the But if an Unless |
Have the same issue when using ->query() Issue is over 2 years old now. return $this->model->search($search)
->query(fn(Builder $query) => $query->with(['mainListingImage']))
->options([
'query_by' => 'vehicle_description, transmission, fuel_type, colour, year'
])
->paginate()
->withQueryString(); |
After spending some time debugging, I've come to the following findings: When using the Details
FixRemove the assignment of |
Wow.. good job @tharropoulos I was able to track down the issue you found but didn't have time to come up with a fix. I wasn't sure if removing the assignment of perPage to the builder's limit attribute won't affect other search engines, because I found it odd that it was there to begin with. I'm happy you're on this problem! |
I've manually tested it but haven't created any new tests to verify. If need be, I'll be sure to include some! Rest of the tests seem to pass as expected |
Scout Version
10.8.6
Scout Driver
Typesense
Laravel Version
10.48.3
PHP Version
8.3.0
Database Driver & Version
MySQL 8.0.36
SDK Version
No response
Meilisearch CLI Version
No response
Description
This is pretty much a reopening of @razvaniacob's issue, who has encountered the same problem I am currently facing. I won't go into too much detail since he described the bug perfectly well in his issue, but Scout's
LengthAwarePaginator
shows wrong total when using Typesense's engineSteps To Reproduce
See steps in #819
The text was updated successfully, but these errors were encountered: