我有3983个BISAC类型的节点。 我无法使用order by检索它们。 这是有效的:
irb(main):024:0* bc = Bisac.all
=> <QueryProxy CYPHER: "MATCH (n:`Bisac`)">
irb(main):025:0> bc.count
CYPHER 796ms MATCH (n:`Bisac`) RETURN count(n) AS n
=> 3983
irb(main):026:0> bc.first
CYPHER 129ms MATCH (n:`Bisac`) RETURN n ORDER BY n.uuid LIMIT {limit_1} | {:limit_1=>1}
=> #<Bisac uuid: "d1c60f13-3c70-11e5-8eb8-22000b18b199", bisac_code: "MUS037050", bisac_value: "MUSIC / Printed Music / Mixed Collections">
irb(main):027:0> bc.last
CYPHER 127ms MATCH (n:`Bisac`) RETURN n ORDER BY n.uuid LIMIT {limit_1} | {:limit_1=>1}
=> #<Bisac uuid: "d1c60f13-3c70-11e5-8eb8-22000b18b199", bisac_code: "MUS037050", bisac_value: "MUSIC / Printed Music / Mixed Collections">
尝试使用订单时,它会失败:
irb(main):033:0* bc = Bisac.order('bisac_code')
=> <QueryProxy CYPHER: "MATCH (result_bisac:`Bisac`) ORDER BY bisac_code">
irb(main):034:0> bc.count
CYPHER 790ms MATCH (result_bisac:`Bisac`) RETURN count(result_bisac) AS result_bisac
=> 3983
irb(main):035:0> bc.first
CYPHER 364ms MATCH (result_bisac:`Bisac`) WITH result_bisac ORDER BY bisac_code RETURN HEAD(COLLECT(result_bisac)) as result_bisac
Neo4j::Session::CypherError: bisac_code not defined (line 1, column 57 (offset: 56))
"MATCH (result_bisac:`Bisac`) WITH result_bisac ORDER BY bisac_code RETURN HEAD(COLLECT(result_bisac)) as result_bisac"
^
from /Users/levi/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/neo4j-core-5.0.10/lib/neo4j-server/cypher_response.rb:211:in `raise_cypher_error'
这里有什么问题?
我的宝石是: neo4j(5.0.14) neo4j-core(5.0.10)
答案 0 :(得分:1)
是的,我可以直接解释的事情! ;)
因此,ORDER BY
不在计数中的原因是因为它只会减慢count
的速度,并且永远不会返回不同的结果。
对于.order
,原因是您传递了String
而不是Symbol
。因为Cypher是一种比SQL更动态的查询语言,所以我一度决定将字符串和符号区别对待。这个想法是,如果你指定一个字符串,你可能想要指定一个更动态的ORDER BY
子句,而你经常使用一个符号来指定你想要排序的属性。这实际上是在Query
的{{1}} API中实现的,但会影响neo4j-core
gem中的ActiveNode
。
所以答案是:
neo4j
尽管如此,这应该记录在案,并且可以做得更聪明。我会创建一个问题,谢谢!