neo4j - Cypher match path based on previous relationship -
I'm trying to ban my pattern matching pattern. I would like to match the next relationship based on the type of relationship used previously.
Here is an example of a simple database:
(a) -1- (b) -2- (c) -1- (e) -2- (F). | 3 ---- (D) ---- 3 Question 1:
start n = node (a), mi = node (f) ) Match P = N- [R *] - M Return P Both should be the result of the path
(A) -1- (B) -2- (c) -1- (e) -2- (f) (a) -1- (b) -3- (d) -3- (e) -2- (f) < However, when the query starting with the node (F) is turned on: start = node (f), n = node (a) match p = m - [R *] -n Return P The result should only be:
(f) -2- (e) -1- (c) -2- (B) -1- (A) path
(f) -2- (e) -3- (d) -3- (b) -1- (a) < / pre> should not be valid because it violates these restrictions:
- You can proceed with coming from a 1-type relationship < Li> Coming from a 2-or-3-type relationship, you can only proceed to -1 -1.
These paths are valid:
() - 1 - () - 2- () () -1) () - 3- () These paths are not valid: = "Text"> First, make a detailed, specific and well-designed question.
Unfortunately, I do not think it's possible that what you want to do with the cipher, I think you need to do this. The cipher is a declarative language; It is, you tell it what you want, and it goes and gets it for you. Using the Travelers API is a compulsory approach to the query; That's it, you tell neo4j exactly how to cross the graph.
Your query here hinders the order in which the relationships are crossed, and which makes a valid path, there is nothing wrong in that, but I believe that the order of traversal The increase in obstacles means that you are saying the cipher how to pass through, and you can not do it with the cipher because it is declarative, another common example of declarative versus compulsory matter is the width vs. the first Search before fly. If you are looking for some nodes, then you can not tell the cipher before the fourth -ths vs depth; You tell it which nodes you want, and it goes and goes to them.
Now, you can be treated like a path and you can filter and reduce work to work with personal relationships but your It is difficult in the query that you need a code, as if something says, "If the first link in a path is 1, then the next 2 or 3 should be". This is actually something that you can do in the Traversal API. Check the interface and you can see how you can write your own method, which you can call Evaluator # evaluate (path path) . Through the right logic will apply General Note, because the declarative query (cipher) hides traversal details from you, it is better to use the IMHO easily declarative query, if you can specify what you want to declare voluntarily but There are cases where you have to control the order of the traversal, and for that you need a traveler. (I have issues where I need some nodes, width-through first search, up to a maximum depth of 3, with complex connection norms - I can not use cipher for it).
To proceed with you in a way, check the link given on the Transcendent Framework, you might describe your query as one, and then keep it handy on neo4j to run it. .
Comments
Post a Comment