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
                ;`;

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).

1 Like

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