简体   繁体   English

Neo4j Cypher模式理解和条件

[英]Neo4j Cypher pattern comprehension and conditions

In my Cypher query I have a following pattern comprehension: 在我的Cypher查询中,我具有以下模式理解:

[ (parentD)<-[:DEFINED_BY]-(ch1:Characteristic)<-[:SET_ON]-(v1:Value)-[:SET_FOR]->(childD) | 
  {characteristicId: id(ch1),  value: v1.value, valueType: ch1.valueType, visualMode: ch1.visualMode} ] AS valuedCharacteristics

I have added parentCharacteristic to my SDN 4 Characteristic entity: 我已将parentCharacteristic添加到我的SDN 4 Characteristic实体中:

@NodeEntity
public class Characteristic extends Votable {

    private final static String DEPENDS_ON = "DEPENDS_ON";

    @Relationship(type = DEPENDS_ON, direction = Relationship.OUTGOING)
    private Characteristic parentCharacteristic;

...

}

Right now I need to extend my pattern comprehension and add a conditions in order to return the same Characteristic set as previously except those who have parentCharacteristic != NULL and pattern comprehension should also return Characteristic that have ID in the {includeCharacteristicIds} collection that I'll provide to this query as parameter. 现在,我需要扩展我的模式理解并添加一个条件,以便返回与以前相同的Characteristic集,但那些具有parentCharacteristic != NULL人和模式理解还应该返回在{includeCharacteristicIds}集合中具有ID Characteristic , ll提供给该查询作为参数。

In order to avoid all Characteristic without child Characteristic I have added following condition: 为了避免没有子Characteristic所有Characteristic ,我添加了以下条件:

WHERE NOT ((ch1)<-[:DEPENDS_ON]-())

So the full pattern comprehension now looks like: 因此,完整的模式理解现在看起来像:

[ (parentD)<-[:DEFINED_BY]-(ch1:Characteristic)<-[:SET_ON]-(v1:Value)-[:SET_FOR]->(childD) WHERE NOT ((ch1)<-[:DEPENDS_ON]-()) | 
  {characteristicId: id(ch1),  value: v1.value, valueType: ch1.valueType, visualMode: ch1.visualMode} ] AS valuedCharacteristics

but how also in additional to this Characteristic list return Characteristic that have ID in the {includeCharacteristicIds} collection ? 但是除了此Characteristic列表之外,还如何返回在{includeCharacteristicIds}集合中具有ID Characteristic

Please help to extend this query. 请帮助扩展此查询。

You can just combine the two conditions with an OR statement like this... 您可以将两个条件与这样的OR语句组合在一起...

WHERE NOT ((ch1)<-[:DEPENDS_ON]-()) OR id(ch1) IN myIDs

The WHERE in a pattern comprehension works just like a WHERE for a MATCH condition. 模式理解中的WHERE就像MATCH条件的WHERE一样。

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

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