is there any way in Neo4J using CONTAINS to compare case-insensitive string?
Asked Answered
S

2

15

Suppose there is a node, Student, that has a property Name.

MATCH (s:Student) were s.Name contains "stack" 
RETURN s.Name

the output should be like : stack, Stack, STACK etc

Saxe answered 20/7, 2017 at 10:31 Comment(3)
Possible duplicate of How can I make a string contain filter on Neo4j CypherHabitation
Seriously, I mean just google Neo4j and contains, it's right there infront of you...Not to mention the duplicate suggestions when you asked the question or the links to the right of this very question.Habitation
He is after a more specific use case - he wants CONTAINS to work without case sensitivity but it is case insensitive. Here is a similar question #44251310 where somebody wanted to search on a value with CONTAINS but have it match all cases of that value.Curley
P
25

You can make the comparison on the upper/lower case version of each, for example:

MATCH (s:Student) 
WHERE toLower(s.Name) CONTAINS toLower("stack")
RETURN s.Name
Peking answered 20/7, 2017 at 18:10 Comment(2)
Disadvantage - If you add toLower() it will not apply Index. :-(Loyalty
we are trying to use full text search index to sovle the above problem, see discussion herePhony
H
10

The regular expression operator, =~, supports case insensitive searches via the (?i) modifier.

This query is the equivalent of yours, except it is case insensitive:

MATCH (s:Student)
WHERE s.Name =~ '(?i).*stack.*'
RETURN s.Name
Helm answered 20/7, 2017 at 21:27 Comment(1)
Disadvantage of this is - Its doesn't apply Index.Loyalty

© 2022 - 2024 — McMap. All rights reserved.