运行不区分大小写的密码查询

gzg*_*gzg 36 case-insensitive neo4j cypher

是否可以在neo4j上运行不区分大小写的cypher查询?

试试这个:http://console.neo4j.org/

当我输入这个:

start n=node(*) 
match n-[]->m 
where (m.name="Neo") 
return m
Run Code Online (Sandbox Code Playgroud)

它返回一行.但是当我输入这个:

start n=node(*) 
match n-[]->m 
where (m.name="neo") 
return m
Run Code Online (Sandbox Code Playgroud)

它不会返回任何东西; 因为名称保存为"Neo".是否有一种简单的方法来运行不区分大小写的查询?

小智 45

是的,通过使用不区分大小写的正则表达式:

WHERE m.name =~ '(?i)neo'
Run Code Online (Sandbox Code Playgroud)

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

  • 链接已经死了.它转移到[http://neo4j.com/docs/developer-manual/current/#query-general](http://neo4j.com/docs/developer-manual/current/#query-general).虽然您的答案包含解决方案,但最好更新链接,以便最终可能会点击它. (2认同)
  • how can I pass parameter here? `'(?i)$param'` and `'(?!)'+$param` doesn't work (2认同)

rot*_*ers 10

另一种方式是:

WHERE LOWER(m.Name) = LOWER("Neo")
Run Code Online (Sandbox Code Playgroud)

如果您使用的是Neo4j客户端(.NET):

Client.Cypher.Match("(m:Entity)")
    .Where("LOWER(m.Name) = LOWER({name})")
    .WithParam("name", inputName)
    .Return(m => m.As<Entity>())
    .Results
    .FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

  • 仅供参考 - LOWER() 已替换为 toLower()。[字符串运算符的文档链接](https://neo4j.com/docs/cypher-manual/current/functions/string/#functions-tolower) (4认同)