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

Pravesh Singh
  • 191
  • 2
  • 8
  • Possible duplicate of [How can I make a string contain filter on Neo4j Cypher](https://stackoverflow.com/questions/24094882/how-can-i-make-a-string-contain-filter-on-neo4j-cypher) – Liam Jul 20 '17 at 12:44
  • 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. – Liam Jul 20 '17 at 12:44
  • 1
    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 https://stackoverflow.com/questions/44250810/neo4j-order-by-relevance#44250930 where somebody wanted to search on a value with CONTAINS but have it match all cases of that value. – Dave Bennett Jul 20 '17 at 13:11

2 Answers2

24

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
William Lyon
  • 8,371
  • 1
  • 17
  • 22
  • 9
    Disadvantage - If you add toLower() it will not apply Index. :-( – Abhi Feb 07 '18 at 11:11
  • we are trying to use [full text search index](https://neo4j.com/docs/cypher-manual/current/indexes-for-full-text-search/) to sovle the above problem, see discussion [here](https://stackoverflow.com/questions/76372597/how-to-apply-a-full-text-search-index-on-an-exiting-neo4j-query/76372727#76372727) – abbood May 31 '23 at 12:07
9

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
cybersam
  • 63,203
  • 6
  • 53
  • 76