Skip to content
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

Open
wants to merge 7 commits into
base: old-prototype-3.x
Choose a base branch
from

Conversation

okoehler
Copy link

@okoehler okoehler commented Jul 11, 2017

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

Copy link
Contributor

@Majkl578 Majkl578 left a 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());
Copy link
Contributor

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.

@Majkl578
Copy link
Contributor

Maybe ICONTAINS would be better naming for this?

@mvrhov
Copy link

mvrhov commented Jul 12, 2017

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
@okoehler
Copy link
Author

This will work only on Mysql, postgresql uses ILIKE keyword for that.

I use LIKE with left and right value converted to lower for multi platform support:

LOWER(fieldname) LIKE (%value%)

@tobiasoberrauch
Copy link

This is exactly what I need. I hope this feature will merged as soon a possible. Thank you for contributing @okoehler

@Ocramius
Copy link
Member

LOWER(fieldname) LIKE (%value%)

This will disable any kind of index usage, unless the column has an index on LOWER(fieldname) (only possible in PostgreSQL and advanced RDBMSs)

@tobiasoberrauch
Copy link

@Ocramius What solution what you suggest?
It would be sad if we don't use this PR

@Ocramius
Copy link
Member

Ocramius commented Aug 1, 2017

@tobiasoberrauch I don't have a solution: I just exposed another problem.

@okoehler
Copy link
Author

@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.
But for now, I think, the benefit is high enough to see this as a first releasable version. So, what do you think, is there any chance to that this PR will be merge?

@Ocramius
Copy link
Member

So, what do you think, is there any chance to that this PR will be merge?

Not until a solution is found here, at least in my opinion. Other @doctrine/doctrinecore folks may disagree.

@sschleue
Copy link

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.
I highly appreciate this PR.

Base automatically changed from master to old-prototype-3.x February 23, 2021 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants