1

我有 3983 个 BISC 类型的节点。我无法使用 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">

尝试使用 order 时失败,如下所示:

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)

4

1 回答 1

1

是的,我可以立即解释的事情!;)

因此,ORDER BY计数中不存在的原因是因为它只会减慢您的速度,count并且永远不会返回不同的结果。

至于.order,原因是因为您传递的是 aString而不是 a Symbol。因为 Cypher 是一种比 SQL 更动态的查询语言,所以我一度决定将字符串和符号区别对待。这个想法是,如果您指定一个字符串,您可能想要指定一个更动态的ORDER BY子句,而通常您将使用符号来指定您想要排序的属性。这实际上是在QueryAPI 中实现的neo4j-core,但它会影响gem。ActiveNodeneo4j

所以答案是:

bc = Bisac.order(:bisac_code)

bc.first

也就是说,这真的应该被记录下来,并且可能变得更聪明。我会创建一个问题,谢谢!

于 2015-08-11T16:42:56.087 回答