alexanoid
alexanoid

Reputation: 25770

Neo4j Cypher pattern comprehension and conditions

In my Cypher query I have a following pattern comprehension:

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

@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.

In order to avoid all Characteristic without child Characteristic I have added following condition:

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 ?

Please help to extend this query.

Upvotes: 0

Views: 323

Answers (1)

Tezra
Tezra

Reputation: 8833

You can just combine the two conditions with an OR statement like this...

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.

Upvotes: 1

Related Questions