How to return all newest nodes from neo4j?

北慕城南 提交于 2019-12-11 06:25:41

问题


Is it possible to query neo4j for the newest nodes? In this case, the indexed property "timestamp" records time in milliseconds on every node.

All of the cypher examples I have lfound concern graph-type queries- "start at node n and follow relationships. What is the general best approach for returning resultsets sorted on one field? Is this even possible in a graph database such as node4j?


回答1:


In the embedded Java API it is possible to add sorting using Lucene constructs.

http://docs.neo4j.org/chunked/milestone/indexing-lucene-extras.html#indexing-lucene-query-objects http://blog.richeton.com/2009/05/12/lucene-sort-tips/

In the server mode you can pass an ?order parameter to the lucene lookup query.

http://docs.neo4j.org/chunked/milestone/rest-api-indexes.html#rest-api-find-node-by-query

Depending on how you indexed your data (not numerically as there are issues with the lucene query syntax parser and numeric searches :( ), in cypher you can do:

start n=node:myindes('time: [1 to 1000]') return n order by n.time asc

There are also more graphy ways of doing that, e.g. by linking the events with a NEXT relationship and returning the head and next n elements from this list

http://docs.neo4j.org/chunked/milestone/cypher-cookbook-newsfeed.html

or to create a tree structure for time:

http://docs.neo4j.org/chunked/milestone/cypher-cookbook-path-tree.html




回答2:


Yes, it is possible, and there are some different ways to do so.

You could either use a timestamp property and a classic index, and sort your result set by that property. Or you could create an in-graph time-based index, like f.e. described in Peter's blog post:

http://blog.neo4j.org/2012/02/modeling-multilevel-index-in-neoj4.html



来源:https://stackoverflow.com/questions/14682598/how-to-return-all-newest-nodes-from-neo4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!