简体   繁体   中英

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

Just for kicks, I looked into the neo4j source code to see if I was missing something. 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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