cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Case insensitive query for a user filter

I'm using neo4j-driver inside of a lambda function. I found the way to run a case insensitive query using regex by adding WHERE m.name =~ '(?i)neo'. This works when I'm not using a parameter. I've tried all of the ways in the following article, but haven't found the special combo that makes it work. Should I be using a where or should I be using =~ with .* and *.?

FilteredUserList: (root, args, context) => {
      return new Promise((resolve, reject) => {
        let session = driver.session();
        let params = { cognitoId: args.cognitoId, textInput: args.textInput };
        let query = `
                MATCH (user:User)
                WHERE user.firstName CONTAINS $textInput OR user.lastName CONTAINS $textInput OR user.email CONTAINS $textInput
                RETURN user
                ;`;
1 ACCEPTED SOLUTION

Just in case anyone wants to do it the unrecommended quick way. I supplied the regex before passing to the query. This is part of a filtering query that looks through users. If you are looking for "Nick" it would allow for "ic", "NICK", "nick"

In frontend before passed

textInput = `(?i).*${textInput}.*`;

In cypher query

AND name =~ $textInput

View solution in original post

3 REPLIES 3

For this type of thing you should probably use the fulltext schema index, something we added in 3.5.x for this type of thing. You'll need to create it and query it through procedures (see the linked docs) but it should allow for case insensitive querying (by default, no need for the regex).

Just in case anyone wants to do it the unrecommended quick way. I supplied the regex before passing to the query. This is part of a filtering query that looks through users. If you are looking for "Nick" it would allow for "ic", "NICK", "nick"

In frontend before passed

textInput = `(?i).*${textInput}.*`;

In cypher query

AND name =~ $textInput

That is the good way. but is there any chance it will use the Index while doing search . I guess regular expression does not use the index. May be slower when the volumn is high.