简体   繁体   English

在Neo4j cypher查询中使用表达式限制

[英]Using expression for limit in Neo4j cypher query

My cypher query is 我的密码查询是

start item= node:jobSearch ("title:Job*") WITH collect(item) as items limit 10  RETURN items as job union start item2= node:jobSearch ("title:Job*") WITH collect(item2) as item2s , count(item2) as paths  match (job1:Job)-[relation]-(relationNode)  where 
(relationNode.name IN ['java','Dance','Programming'] OR relation.duration IN 
['java','Dance','Programming']) AND  NOT (job1 IN item2s) AND paths < 10   RETURN  job1  as job limit 8

where I have used limit 8 in above query , I want to use 10 - paths . 我在上面的查询中使用了限制8,我想使用10 - 路径。 How can i use this ? 我怎么用这个?

So it would seem that you should be able to do this with an expression in the limit clause, or perhaps by computing the right integer in your last WITH statement, (eg WITH (10-paths) as resultCount (...) limit resultCount ) but I tested this and it won't work. 因此,您似乎应该能够使用limit子句中的表达式执行此操作,或者可能通过在上一个WITH语句中计算正确的整数(例如, WITH (10-paths) as resultCount (...) limit resultCount )但我测试了它,它将无法正常工作。

Just for kicks, I looked into the neo4j source code to see if I was missing something. 只是为了踢,我查看neo4j源代码,看看我是否遗漏了一些东西。 In this source file you can see some of the rules for clauses and parsing of the cypher language itself. 在这个源文件中,您可以看到一些条款和解密密码语言本身的规则。

The bad news is that the LIMIT expression expects either an unsigned integer literal, or a parameter. 坏消息是LIMIT表达式要求无符号整数文字或参数。 So basically you can't do what you're asking to do, unless you compute (10-paths) in a separate query, then put into this query a {resultCount} parameter, and then give it that pre-computed value. 所以基本上你不能做你要做的事情,除非你在一个单独的查询中计算(10-paths) ,然后在{resultCount}参数中加入该查询,然后给它预先计算的值。 That would probably be a lot of work for not much value. 这可能是很多工作,没有多大价值。

On the upside, unless your results are really monstrously huge, it's probably easiest to just LIMIT 10 and include the integer paths in your result set so that the code that consumes these results knows to ignore any more results than that. 从好的方面来说,除非你的结果非常巨大,否则最简单的就是LIMIT 10并在结果集中包含整数paths ,以便使用这些结果的代码知道忽略了比这更多的结果。

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

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