简体   繁体   English

Neo4j-查询结果随机顺序

[英]Neo4j - Query results random order

I'm not exactly sure what's gone on inside my app but my queries don't seem to give me my results in order of creation. 我不确定我的应用程序内部发生了什么,但是我的查询似乎并没有按照创建的顺序给出结果。 It recently rearranged itself without me changing the code related to the query. 它最近重新排列了自己,而无需更改与查询有关的代码。 However, I've obviously done SOMETHING. 但是,我显然已经做了一些事情。

At one point I was trying to get my rails c results writen into a file. 有一次,我试图将rails c结果写入文件中。 However, that was simply writing the output of the query to the file. 但是,这只是将查询的输出写入文件。 I didn't think that would effect query orders... 我认为这不会影响查询顺序...

The queries were simply like 查询就像

File.open('text.txt', 'w') do |f|
   User.all.each do |u|
      f.puts u.email
   end
end

I think I can re-sort one of my relationships by adding property :created_at and sorting it by that timestamp. 我认为可以通过添加property :created_at并按该时间戳对其进行排序来对我的一种关系进行重新排序。

But there is no way for me to do this with my Q+A association as they aren't activerel right now. 但是我无法通过我的Q + A协会来做到这一点,因为它们目前还不是activerel。

It's called like this 这样叫

<% @event.event_questions.each do |q| %>

In the app there were 3 questions created. 在应用程序中,创建了3个问题。 The order that it ended up showing was 最终显示的顺序是

2,1,3 2,1,3

How does the neo4j query determine the order of the objects? neo4j查询如何确定对象的顺序? What could I have possibly done wrong? 我可能做错了什么?

I don't think that neo4j has any way of determining the date/time of when nodes are created. 我认为neo4j无法确定创建节点的日期/时间。 It stores an internal, incrementally generated numeric ID, but those IDs can be recycled when you restart your server. 它存储内部递增生成的数字ID,但是当您重新启动服务器时可以回收这些ID。 It could be that order changed after you restarted your server. 重新启动服务器后,顺序可能会更改。 I'm not sure if neo4j returns nodes in any sort of order by default. 我不确定neo4j默认情况下是否以任何顺序返回节点。 I'm assuming it doesn't guarantee order unless you specify an ORDER BY 我假设它不能保证订单,除非您指定ORDER BY

For the ordering of relationships without ActiveRel , you can do: 对于没有ActiveRel的关系的排序,您可以执行以下操作:

@event.event_questions(:question, :rel).order('rel.created_at')

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

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