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 search (via regex operator) in MongoDB #11

Open
PatrickHuetter opened this issue Aug 16, 2016 · 5 comments
Open

Case insensitive search (via regex operator) in MongoDB #11

PatrickHuetter opened this issue Aug 16, 2016 · 5 comments

Comments

@PatrickHuetter
Copy link

It would be fine to have the possibility to search case insensitive within mongodb.

At this time a query like this is needed to include lower case words:
title=re=.*Bluetooth.* or title=re=.*bluetooth.*

@matthew-b-payne
Copy link

Agreed. Even an case a insensitive substring search?

title=~=luetooth

@RutledgePaulV
Copy link
Owner

I've largely operated under the thinking that regular expressions are enough for the problems listed here until they prove to be unacceptable for some reason. Historically, mongo's case sensitivity story has not been great until just last month:

https://jira.mongodb.org/browse/SERVER-90

If there's a way to benefit from the recent developments in mongo I would probably recommend it be implemented as a custom visitor if possible!

@matthew-b-payne
Copy link

Can you document how to express regex case insensitive substring match in
url form?

For clients transforming:

q=~=mith (finds Smiths)
to the case-insensitive regex criteria would simplify things.

On Thu, Sep 22, 2016 at 2:13 PM, Paul Rutledge [email protected]
wrote:

I've largely operated under the thinking that regular expressions are
enough for the problems listed here until they prove to be unacceptable for
some reason. Historically, mongo's case sensitivity story has not been
great until just last month:

https://jira.mongodb.org/browse/SERVER-90

If there's a way to benefit from the recent developments in mongo I would
probably recommend it be implemented as a custom visitor if possible!


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#11 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABFkK1goN-3_t5ol1lOZjXWx1Az_QnGRks5qssVWgaJpZM4JlPED
.

@SSaev
Copy link

SSaev commented Feb 22, 2017

Hi guys,

I would like to up vote this issue.
Our current setup is MongoDB 3.4 with featureCompatibilityVersion set to 3.4 and on collection level we have set collations with strength 2.
When we are filtering for exact match we achieve the case insensitivity, for example suppose I have a user with first name set to "Svetlin" both calls:

/users?q=firstName==Svetlin
/users?q=firstName==svetlin

will result in finding this user.

However, now we want to achieve autocompletion (sth like a "like" statement in regular RDBs). Of course, as we are using mongo we use the regex filtering, sth like:

/users?q=firstName=re=Sve.* (correctly retrieves the above user)

Unfortunately, I would expect that

/users?q=firstName=re=sve.*

will also work, which is not the case. Any suggestions how I can achieve both case insensitivity and autocompletion?

Best regards,
Svetlin

@jmathewt
Copy link

jmathewt commented Jan 15, 2019

We had the same issue. One of the senior guys in our team found out the code in q-builders and came up with overriding the MongoVisitor class - https://github.com/RutledgePaulV/q-builders/blob/develop/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/MongoVisitor.java, so create your own

public class CustomMongoVisitor extends MongoVisitor{
           @Override
            protected Criteria visit(ComparisonNode node) {
             // all the existing code of that function
             // just change 
                       else if (ComparisonOperator.RE.equals(operator)) {
                            return where(field).regex((String)single(values), "i"); // adding case insensitive using i
                        }
             }
}```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants