Running a case-insensitive cypher query

2019-02-04 01:05发布

Is it possible to run a case-insensitive cypher query on neo4j?

Try that: http://console.neo4j.org/

When I type into this:

start n=node(*) 
match n-[]->m 
where (m.name="Neo") 
return m

it returns one row. But when I type into this:

start n=node(*) 
match n-[]->m 
where (m.name="neo") 
return m

it does not return anything; because the name is saved as "Neo". Is there a simple way to run case-insensitive queries?

3条回答
太酷不给撩
2楼-- · 2019-02-04 01:16

Another way would be:

WHERE LOWER(m.Name) = LOWER("Neo")

And if you are using the Neo4j Client (.NET):

Client.Cypher.Match("(m:Entity)")
    .Where("LOWER(m.Name) = LOWER({name})")
    .WithParam("name", inputName)
    .Return(m => m.As<Entity>())
    .Results
    .FirstOrDefault();
查看更多
Root(大扎)
3楼-- · 2019-02-04 01:22

Yes, by using case insensitive regular expressions:

WHERE m.name =~ '(?i)neo'

http://neo4j.com/docs/developer-manual/current/cypher/clauses/where/#where-case-insensitive-regular-expressions

查看更多
地球回转人心会变
4楼-- · 2019-02-04 01:35

If anybody is looking on how to do this with a parameter, I managed to do it like this.

query = "{}{}{}".format('Match (n) WHERE n.pageName =~ "'"(?i)", name, '" RETURN n')

and "name" is the variable or your parameter

查看更多
登录 后发表回答