-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Spatie Query Builder Partial doesnt work #3271
-
Looking at this, this is the cause why
By default, all values passed to allowedFilters are converted to partial filters. The underlying query will be modified to use a LIKE LOWER(%value%) statement. Because this can cause missed indexes, it's often worth considering a beginsWithStrict filter for the beginning of the value, or an endsWithStrict filter for the end of the value. These filters will use a LIKE value% statement and a LIKE %value statement respectively, instead of the default partial filter. This can help optimize query performance and index utilization.
Would anyone share their custom filter solution that can replace this?
https://spatie.be/docs/laravel-query-builder/v6/features/filtering#content-custom-filters
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
This should be implemented using Regex.
Partial
:$builder->where('field', new MongoDB\BSON\Regex(preg_quote($value), 'i'));
BeginsWithStrict
:$builder->where('field', new MongoDB\BSON\Regex('^'.preg_quote($value), ''));
EndsWithStrict
:$builder->where('field', new MongoDB\BSON\Regex(preg_quote($value).'$', ''));
This should be done in the spacie project, if they accept to add support for MongoDB. I asked spatie/laravel-query-builder#995
Beta Was this translation helpful? Give feedback.