2017-03-01 122 views
0

在我的Neo4j/SDN4項目找到實體我有以下節點實體:Neo4j的Cypher支架由相關節點的準確集合(IDS)

@NodeEntity 
public class Nomination extends Commentable { 

    private final static String CONTAINS = "CONTAINS"; 
    private final static String DEFINED_BY = "DEFINED_BY"; 

    private String name; 

    @Relationship(type = CONTAINS, direction = Relationship.OUTGOING) 
    private Set<Criterion> criteria = new HashSet<>(); 

... 

} 

我需要實現一個暗號查詢,將嘗試找到Nomination確切收集相關標準(按標準ID)。

現在我有以下查詢:

MATCH (n:Nomination)-[:CONTAINS]->(c:Criterion) WHERE id(n) = {nominationId} AND id(c) IN {criterionIds} RETURN n 

,但它是不夠的,因爲Nomination可以包含在{criterionIds}提供較少的標準,但我需要檢查精確匹配(標準順序不問題)

如何重新執行此查詢以執行此操作?

回答

0

這裏的另一種方法,你可能要分析每一個,看看哪個最適合你:

MATCH (c:Criterion) 
WHERE id(c) in {criterionIds} 
WITH COLLECT(c) as criterion 
WITH criterion, head(criterion) as firstC 
MATCH (firstC)<-[:CONTAINS]-(n:Nomination) 
WHERE SIZE((n)-[:CONTAINS]->(:Criterion)) = SIZE(criterion) 
AND ALL(crit in criterion[1..] WHERE (n)-[:CONTAINS]->(crit))  
RETURN n 
+0

感謝這個解決方案! – alexanoid

相關問題