所以,我正在尝试使用DSL重写以下Cypher。
match (n)
where n.code =~ {prefix}
and n.code =~ '.*-(\d+){5}'
with n.code as text,
'-' as mark
with reduce(
last = 0, pos in range(0, length(text) - 1) |
case substring(text, pos, length(mark))
when mark then pos
else last
end
) as idx,
text
return substring(text, idx + 1) as next
order by next desc
limit 1
基本思路是:
- 给出一个代码为:"XXXX-00000"的结构。4个字符和5个数字
- 当输入是"前缀"时,如"XXXX-"部分。
- 查找"00000"部分的最后一个数字
我无法找到任何FunctionExpression来创建REDUCE。我看错了吗?或者它还没有在2.1.4中实现我对它的依赖如下:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-cypher-dsl</artifactId>
<version>2.1.4</version>
</dependency>
可能有一个更简单的方法,使用split函数。
你可以这样做:
with split('XXXXX-00000', '-') as parts return parts[0], parts[1];
那么:
MATCH (n)
WITH n, split(n.code, '-') as parts
WHERE parts[0] = {prefix}
return parts[1] order by parts[1] limit 1;