-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Case insensitive like #6547
base: old-prototype-3.x
Are you sure you want to change the base?
Case insensitive like #6547
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs functional tests.
@@ -186,6 +186,11 @@ public function walkComparison(Comparison $comparison) | |||
$this->parameters[] = $parameter; | |||
|
|||
return $this->expr->like($field, $placeholder); | |||
case Comparison::CONTAINS_CI: | |||
$parameter->setValue('%' . strtolower($parameter->getValue()) . '%', $parameter->getType()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use multibyte safe variant, mb_strtolower.
Maybe |
This will work only on Mysql, postgresql uses ILIKE keyword for that. |
- use multibyte safe variant mb_strtolower
- convert value for comparison to lowercase if ICONTAINS
I use LIKE with left and right value converted to lower for multi platform support:
|
This is exactly what I need. I hope this feature will merged as soon a possible. Thank you for contributing @okoehler |
This will disable any kind of index usage, unless the column has an index on |
@Ocramius What solution what you suggest? |
@tobiasoberrauch I don't have a solution: I just exposed another problem. |
@Ocramius I created this PR to provide a feature which some people are missing. I created tests, it works for all supported databases. Of course there are some possible improvements, which could be created if there is a need for. |
Not until a solution is found here, at least in my opinion. Other @doctrine/doctrinecore folks may disagree. |
In my opinion the usage of indexes is nice to have not mandatory. This (some kind of slow) solution is better than none. Case insensitive like would be a very nice feature. Else you always have to build it on your own which bloats your code and makes it ugly. I think a notice in documentation should be enough to be aware of that performance issue. At least for now. |
This pull request adds Comparison::ICONTAINS to create a case insensitive like.
Existing case sensitive like
fieldname LIKE %value%
New case insensitive like
LOWER(fieldname) LIKE (%value%)
with value converted to lowercase by php, and fieldname surrounded by platforms lower function.
UnitTests will run if you use this version of doctrine collections. See doctrine collections PR#123