gpt4 book ai didi

regex - Neo4j 2.0 通配符搜索标签名称

转载 作者:行者123 更新时间:2023-12-04 17:35:35 25 4
gpt4 key购买 nike

在 Cypher 中处理属性时,您可以使用正则表达式来匹配属性值,如下所示:

Match (n)-[:IS_A]-() where (n:Course_Driving_001) and (n.name =~ '(?i).*criteria.*' or n.description =~ '(?i).*criteria.*')   return distinct n limit 20;

我想用标签名称做同样的事情。我想获得包含某个字符串的所有唯一标签。就像是:
 Match (n)-[:IS_A]-() where (n:Course_*_001) return distinct n;

Cypher可以做到吗?还是 RestAPI?常用表达?

我正在使用 Neo4j 2.0 版本。

最佳答案

您不能直接在标签上使用正则表达式。但是使用 labels功能这是可能的:

MATCH (n)-[:IS_A]->() 
WHERE any(l IN labels(n) WHERE l=~'Course_*_001')
RETURN distinct n;

请注意,此查询可能会很昂贵,因为它涉及数据库中的所有节点。您可能希望重构数据模型以使用多个标签,例如 CourseCourse_xyz_001 .在这种情况下,您可以使用 MATCH (n:Course) ....这减少了首先要访问的节点数量。

关于regex - Neo4j 2.0 通配符搜索标签名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20646572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com