Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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_Cypher - Fatal编程技术网

Neo4j密码和索引号

Neo4j密码和索引号,neo4j,cypher,Neo4j,Cypher,例如,我有一个以下查询: MATCH (p:Product) ORDER by p.createDate DESC RETURN p 我知道一些产品的id,比如说p.id=10 使用Cypher查询是否可以在查询结果中获取此产品的索引号?如果是的话,你能举个例子吗 例如,此查询返回具有ID的以下产品: 1, 4, 45, 32, 67, 10, 95, 2 因此,id=10的产品的索引号是6这应该有效: MATCH (p:Product) WITH p ORDER by p.createDa

例如,我有一个以下查询:

MATCH (p:Product) ORDER by p.createDate DESC RETURN p
我知道一些产品的
id
,比如说
p.id=10

使用Cypher查询是否可以在查询结果中获取此产品的索引号?如果是的话,你能举个例子吗

例如,此查询返回具有ID的以下产品:

1, 4, 45, 32, 67, 10, 95, 2
因此,
id=10的产品的索引号是
6

这应该有效:

MATCH (p:Product)
WITH p ORDER by p.createDate DESC
WITH COLLECT(p) AS ps
RETURN
  ps,
  REDUCE(ix = -1, i IN RANGE(0, SIZE(ps)-1) | CASE ps[i].id WHEN 10 THEN i ELSE ix END) AS ix;
这应该返回
产品的排序集合
id
为10(或-1,如果找不到)的(最后一个)产品的(0-origin)索引。

MATCH (p:Product)
WITH p ORDER by p.createDate DESC
WITH COLLECT(p) AS ps
RETURN
  ps,
  REDUCE(ix = -1, i IN RANGE(0, SIZE(ps)-1) | CASE ps[i].id WHEN 10 THEN i ELSE ix END) AS ix;

这将返回
产品的排序集合
id
为10(或-1,如果找不到)的(最后一个)产品的(0-origin)索引。

这里没有固有索引,因此您需要手动将其添加到查询中,并且需要使用集合来完成此操作

MATCH (target:Product {id:10}) // should be fast with an index
MATCH (p:Product) 
WITH p
ORDER by p.createDate DESC 
WITH collect(p) as products
UNWIND range(0, size(products) - 1) as index
WITH index, products[index] as product
WHERE product = target
RETURN index, product

这里没有固有的索引,因此需要手动将其添加到查询中,并且需要使用集合来完成此操作

MATCH (target:Product {id:10}) // should be fast with an index
MATCH (p:Product) 
WITH p
ORDER by p.createDate DESC 
WITH collect(p) as products
UNWIND range(0, size(products) - 1) as index
WITH index, products[index] as product
WHERE product = target
RETURN index, product

如果您可以访问APOC程序,您还可以利用一些收集功能来获取所需:

MATCH (target:Product {id:10}) // should be fast with an index
MATCH (p:Product) 
WITH p
ORDER by p.createDate DESC 
WITH collect(p) as products
RETURN target, apoc.coll.indexOf(products, target) as index

如果您可以访问APOC程序,您还可以利用一些收集功能来获取所需:

MATCH (target:Product {id:10}) // should be fast with an index
MATCH (p:Product) 
WITH p
ORDER by p.createDate DESC 
WITH collect(p) as products
RETURN target, apoc.coll.indexOf(products, target) as index

10的索引实际上是5,使用传统的0原点索引。10的索引实际上是5,使用传统的0原点索引。非常感谢!还有一个问题-从性能的角度来看,在一个大型集合上,这是一项繁重的操作吗。。假设5000-10000个元素?
REDUCE
具有
O(N)
复杂性,因此它不会“轻”。但是我认为你不能在
O(N)
上有所改进。很遗憾,Cypher不支持提前中止
REDUCE
。非常感谢!还有一个问题-从性能的角度来看,在一个大型集合上,这是一项繁重的操作吗。。假设5000-10000个元素?
REDUCE
具有
O(N)
复杂性,因此它不会“轻”。但是我认为你不能在
O(N)
上有所改进。不幸的是,Cypher不支持提前中止
REDUCE
。抱歉,但是在这个查询中,在哪里放置Id=10的条件?啊,我误解了这个问题,我认为这是要求返回索引以及所有行。我会编辑。对不起,但是在这个查询中,在哪里放置Id=10的条件?啊,我误解了这个问题,我认为这是要求返回索引以及所有行。我来编辑。