Neo4j TimeTree REST API Previous and Next Navigation

后端 未结 2 1201
别跟我提以往
别跟我提以往 2021-01-15 06:15

I am currently using Neo4j TimeTree REST API and is there any way to navigate to the time before and after a given timestamp? My resolution is Second and I just realize that

相关标签:
2条回答
  • 2021-01-15 06:20

    Leaving aside for a moment the specific use of TimeTree, I'd like to describe how to generally manage a doubly-linked list using SDN 4, specifically for the case where the underlying graph uses a single relationship type between nodes, e.g.

    (post:Post)-[:NEXT]->(post:Post)
    

    What you can't do

    Due to limitations in the mapping framework, it is not possible to reliably declare the same relationship type twice in two different directions in your object model, i.e. this (currently) will not work:

    class Post {
       @Relationship(type="NEXT", direction=Relationship.OUTGOING)
       Post next;
    
       @Relationship(type="NEXT", direction=Relationship.INCOMING)
       Post previous;
    }
    

    What you can do

    Instead we can combine the @Transient annotation with the use of annotated setter methods to obtain the desired result:

    class Post {
       Post next;
    
       @Transient Post previous;
    
       @Relationship(type="NEXT", direction=Relationship.OUTGOING)
       public void setNext(Post next) {
          this.next = next;
          if (next != null) {
              next.previous = this;
          }
       }
    }
    

    As a final point, if you then wanted to be able to navigate forwards and backwards through the entire list of Posts from any starting Post without having to continually refetch them from the database, you can set the fetch depth to -1 when you load the post, e.g:

    findOne(post.getId(), -1);
    

    Bear in mind that an infinite depth query will fetch every reachable object in the graph from the matched one, so use it with care!

    Hope this is helpful

    0 讨论(0)
  • 2021-01-15 06:24

    The Seconds are linked to each other via a NEXT relationship, even across minutes.

    Hope this is what you meant enter image description here

    0 讨论(0)
提交回复
热议问题