-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Fix for using pagination with custom query in Scout Builder. #290
Fix for using pagination with custom query in Scout Builder. #290
Conversation
Enhanced the SearchFactory to handle 'limit' from the builder and set the search size accordingly. Also included unit tests to verify limit handling and compatibility with pagination options.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #290 +/- ##
============================================
+ Coverage 96.06% 96.21% +0.14%
- Complexity 201 204 +3
============================================
Files 36 36
Lines 636 661 +25
============================================
+ Hits 611 636 +25
Misses 25 25 ☔ View full report in Codecov by Sentry. |
Great work on this pull request! The addition to set the size based on the builder's limit is a valuable enhancement. However, I've noticed that When Restricting the usage of both to avoid conflicts What do you think? |
@matchish this update maintains backward compatibility, as it only applies limit handling for pagination, following the same approach as Eloquent's paginator, which ignores limit and offset when paginating. |
Yes, it follows the same approach as Eloquent's paginator, but I'm not sure about backward compatibility. For example, if someone is using I understand that no reason to write code this way, but someone could forget to remove after experiments. I just prefer to not bump to new major version if it is not necessary. Would it cause any issues if we keep the |
We will have to abandon support for the |
Simplify and centralize option preparation by introducing the `prepareOptions` and `supportedOptions` methods in `SearchFactory`. Adjust tests to align with the new logic, ensuring size and from parameters are correctly set and prioritized.
I made suggested changes and added some behavioral tests. |
Don't forget to update |
@matchish which version I should use? |
Not sure what is happening but looks like not only we have failed upload to codecov codecov/codecov-action#1580 (comment) |
I'm thinking about
|
I updated version in the changelog. |
Quality Gate passedIssues Measures |
replaced codecov with sonarcloud. could you pull master to your branch? |
Branch merged |
Released! Thank you for your valuable contribution! Great Job! |
Problem
When calling the paginate method on
Laravel\Scout\Builder
, thegetTotalCount
method is triggered.The
getTotalCount
method retrieves the total count of results from the search engine. It includes a check for a query callback, which may trigger an additional database query if specified.Additionally, the default
take
method onLaravel\Scout\Builder
does not allow setting a response size limit in this implementation.Proposed Fix
In the
SearchFactory::create
method, add a check for the presence of the$builder->limit
parameter before examining the$options
parameter. This adjustment preserves compatibility with the pagination implementation by ensuring that any explicitly set limit in $builder is prioritized.This change will allow the pagination functionality to respect a custom limit if defined, while maintaining backward compatibility with existing configurations.