Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

neo4j

cypher

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

like image 836
Pravesh Singh Avatar asked Jul 20 '17 10:07

Pravesh Singh


People also ask

Is Neo4j case sensitive?

Neo4j database is case sensitive. By default, property values are matched by Bloom in a case sensitive fashion, if they begin with any of the matching tokens input by the user. If you would like search suggestions to be case insensitive, you can enable Case insensitive search and suggestions under Bloom settings.

What is optional match in Neo4j?

An OPTIONAL MATCH matches patterns against your graph database, just like a MATCH does. The difference is that if no matches are found, OPTIONAL MATCH will use a null for missing parts of the pattern. OPTIONAL MATCH could be considered the Cypher equivalent of the outer join in SQL.

Which clause is used to search the data with a specified pattern in Neo4j?

The MATCH clause allows you to specify the patterns Neo4j will search for in the database.

What is unwind in Neo4j?

With UNWIND , you can transform any list back into individual rows. These lists can be parameters that were passed in, previously collect -ed result or other list expressions. One common usage of unwind is to create distinct lists. Another is to create data from parameter lists that are provided to the query.


2 Answers

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
like image 119
cybersam Avatar answered Dec 23 '22 11:12

cybersam


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
like image 32
William Lyon Avatar answered Dec 23 '22 12:12

William Lyon