Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Spatie Query Builder Partial doesnt work #3271

Unanswered
masterbater asked this question in Q&A
Discussion options

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.

https://github.com/spatie/laravel-query-builder/blob/dc7c17a9dfc2df44d108a696cbc20158af622fa3/src/Filters/FiltersPartial.php

Would anyone share their custom filter solution that can replace this?
https://spatie.be/docs/laravel-query-builder/v6/features/filtering#content-custom-filters

You must be logged in to vote

Replies: 1 comment

Comment options

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

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /