【问题标题】:Neo4j Cypher pattern comprehension and conditionsNeo4j Cypher 模式理解和条件
【发布时间】:2017-05-07 11:33:51
【问题描述】:

在我的 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

我已将 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;

...

}

现在我需要扩展我的模式理解并添加一个条件,以便返回与以前相同的 Characteristic 集,除了那些具有 parentCharacteristic != NULL 和模式理解的人也应该返回 Characteristic 具有 ID 在我将作为参数提供给此查询的 {includeCharacteristicIds} 集合。

为了避免所有Characteristic 没有孩子Characteristic 我添加了以下条件:

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

所以完整的模式理解现在看起来像:

[ (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

但是除了这个Characteristic 列表还返回Characteristic{includeCharacteristicIds} 集合中有ID 吗?

请帮助扩展此查询。

【问题讨论】:

    标签: neo4j cypher


    【解决方案1】:

    您可以将这两个条件与这样的 OR 语句结合起来......

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

    模式理解中的 WHERE 就像 MATCH 条件的 WHERE 一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多