Rewrite query builder to support all missing methods #761
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rewrite query builder to support all missing methods
I have performed a complete internal rewrite of the
where
method in theLaravel/Scout
package to natively support Laravel query builder methods. This allows for more flexible queries that supportAND
,OR
, and combined multiple scopes using closures.Current state supporting only
AND
operator:If we need to implement a filter using OR:
What about more custom filters?
The code starts to feel bloated and difficult to maintain. With this contribution, it is now possible to filter between
age = 38 OR name = 'Edgar'
using a cleaner syntax:The enhanced query builder also supports custom filters, making it easier to create complex queries. For example, filtering based on age, name, and a list of excluded IDs can be accomplished as follows:
I have ported missing functions from
Illuminate\Database\Query\Builder
intoLaravel\Scout\Builder
. These includewhere
,orWhere
,whereIn
,orWhereIn
,whereNotIn
,orWhereNotIn
,whereExists
,orWhereExists
,whereNotExists
,whereBetween
,whereNull
,orWhereNull
,whereNotNull
,whereIsEmpty
,orWhereIsEmpty
,whereIsNotEmpty
, enabling us to practically use the same functionality as with Eloquent models.I'm currently working on extending this functionality to support Algolia. Until this transition is complete, I've added a helper method
enableMeilisearchNewQueryBuilder
that allows users to enable the new query builder features:Benefits:
I'm actively working on extending this functionality to support Algolia, which will complete the transition to using this new query builder across different search engines. Further discussions and collaboration on this are welcome.
Please review and provide feedback on this pull request. Your input is greatly appreciated.
Thank you for your time and consideration.