简体   繁体   English

Neo4j Cypher 查询以查找具有完全匹配的节点(AND 而不是 OR)

[英]Neo4j Cypher query to find nodes with exact match (AND instead of OR)

I'm trying to create a query that bring me some node that have the exact match with a set of nodes.我正在尝试创建一个查询,为我带来一些与一组节点完全匹配的节点。 In this case I wanna bring experiences that have tags, for example, what experiences have tags: "food" AND "nightlife" AND "culture".在这种情况下,我想带来带有标签的体验,例如,哪些体验带有标签:“食物”和“夜生活”和“文化”。

My query is "working", but bringing the result using OR instead of AND.我的查询是“工作”,但使用 OR 而不是 AND 带来结果。 How can I fix it?我该如何解决?

I'm not sure if I'm using de correct approach of the我不确定我是否使用了正确的方法

@Query("START experience = node:__types__(className=\"...\"), tags = node({0}) " +
  "WHERE experience-[:TAGGED]->tags " +
  "RETURN experience")
public Set<Experience> findExperiencesByTags(Set<Long> tagIds);

I'm using Spring Data 2.0.1 and neo4j 1.6.3.我正在使用 Spring Data 2.0.1 和 neo4j 1.6.3。

try to divide it into 3 separate MATCH phrases:尝试将其分成 3 个单独的 MATCH 短语:

"MATCH experience-[:TAGGED]->tags1, experience-[:TAGGED]->tags2,  experience-[:TAGGED]->tags3, " +
"WHERE tags1.tag='food' AND tags2.tag='culture' AND tags3.tag='nightlife' "

I agree with @ulkas我同意@ulkas

If you really want to pass in an arbitrary number of tags you can try this, but it will probably perform not as good as the explicit matches.如果你真的想传入任意数量的标签,你可以试试这个,但它的性能可能不如显式匹配。

START tags = node({0}) 
MATCH experience-[:TAGGED]->tags
WITH experience, count(*) as cnt
WHERE cnt = length({0})
RETURN experience

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM