Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
仅当Neo4j中存在多个属性时,才检查它们的值_Neo4j_Conditional_Cypher - Fatal编程技术网

仅当Neo4j中存在多个属性时,才检查它们的值

仅当Neo4j中存在多个属性时,才检查它们的值,neo4j,conditional,cypher,Neo4j,Conditional,Cypher,我有一些属性的x型节点。 我试图形成一个查询,检查x中是否存在一组给定的属性,如果存在,则将每个属性与一个值进行比较,然后返回相关节点。psuedo代码如下所示:- match(x) if exist(x.a, x.b) then if(x.a==1 and x.b==2) return x else if exist(x.a) then if(x.a==1) return x else if exist(x.b) then if(x.b==

我有一些属性的x型节点。 我试图形成一个查询,检查x中是否存在一组给定的属性,如果存在,则将每个属性与一个值进行比较,然后返回相关节点。psuedo代码如下所示:-

match(x)
if exist(x.a, x.b)
   then if(x.a==1 and x.b==2)
         return x
else if exist(x.a)
   then if(x.a==1)
         return x
else if exist(x.b)
   then if(x.b==1)
         return x
match(x) where x.a='high' return x union match(x) where x.b='high' return x
我试过:-

MATCH (x) WHERE exists(x.a) and ('high' IN (x.a)) and exists(x.b) and ('high' IN (x.b)) RETURN x
以及:-

但这两个查询的问题是,如果说“a”不是x中的属性,而“b”是,那么它返回null而不给出至少基于“b”值的结果。我想这是因为and条款,但我找不到替代方案。 我正在使用neo4j 3.1.3

这可能会起作用:

CREATE (:X {a: "first a"})
CREATE (:X {a: "second a", b: "first b"})
CREATE (:X {b: "second b"})

MATCH (x:X)
WHERE exists(x.a)
AND exists (x.b)
AND <any other conditions>
RETURN x
UNION 
MATCH (x:X)
WHERE exists(x.a)
AND NOT exists (x.b)
AND <any other conditions>
RETURN x
UNION 
MATCH (x:X)
WHERE NOT exists(x.a)
AND exists (x.b)
AND <any other conditions>
RETURN x;
CREATE(:X{a:“第一个a”})
创建(:X{a:“第二个a”,b:“第一个b”})
创建(:X{b:“第二个b”})
匹配(x:x)
存在的位置(x.a)
并存在(x.b)
及
返回x
联合
匹配(x:x)
存在的位置(x.a)
并且不存在(x.b)
及
返回x
联合
匹配(x:x)
不存在的地方(x.a)
并存在(x.b)
及
返回x;
由于这三个案例返回相同的内容,您可以指定这三个案例并将它们合并在一起

希望这有帮助,
Tom

在这种情况下,UNION操作符将提供帮助,使查询如下:-

match(x)
if exist(x.a, x.b)
   then if(x.a==1 and x.b==2)
         return x
else if exist(x.a)
   then if(x.a==1)
         return x
else if exist(x.b)
   then if(x.b==1)
         return x
match(x) where x.a='high' return x union match(x) where x.b='high' return x

从上面的答案中得到了这个想法

你可以和工会合作,把三个不同的案例联系起来。所以工会似乎是解决问题的方法。使用union时,仅存在我不需要检查的编辑实体。因此,查询如下:-match(x)where x.a='high'返回x union match(x)where x.b='high'返回x谢谢!