[英]How to traverse an order list of node properties in neo4j?
I'm new to neo4j , so your help is appreciated.我是 neo4j 的新手,因此感谢您的帮助。
I have a neo4j database with nodes that have a property "Color" and two relationship types, "Previous" and "Next".我有一个 Neo4j 数据库,其节点具有属性“颜色”和两种关系类型,“上一个”和“下一个”。 I have an ArrayList that contains node properties in the order they should be traversed, for example Blue, Red, Yellow.我有一个 ArrayList,它包含节点属性,按照它们应该被遍历的顺序,例如蓝色、红色、黄色。
How do I traverse the graph to find if the exact path Node(Color:Blue) --> Node(Color:Red) --> Node(Color:Yellow) with no nodes in between and all relationships of type "Next", exists in the database?如何遍历图形以查找确切路径 Node(Color:Blue) --> Node(Color:Red) --> Node(Color:Yellow) 之间是否没有节点以及所有类型为“Next”的关系,存在于数据库中?
I'm using neo4j embedded in a java application.我正在使用嵌入在 Java 应用程序中的 neo4j。
It's probably enough with a NEXT relationship between each, because an incoming NEXT can be considered as "previous".每个之间的 NEXT 关系可能就足够了,因为传入的 NEXT 可以被视为“前一个”。
And I think you should index your colors and then start traversing from the first node (in this case "Blue") and have a traverser like this:我认为你应该索引你的颜色,然后从第一个节点(在这种情况下为“蓝色”)开始遍历,并有一个像这样的遍历器:
String[] colors = new String[] { "Blue", "Red", "Yellow" }; Node start = db.index().forNodes( "colors" ).get( "color", colors[0] ).getSingle(); Traversal.description().uniqueness( Uniqueness.RELATIONSHIP_GLOBAL ).breadthFirst().relationships( Types.NEXT, Direction.OUTGOING ).evaluator( new Evaluator() { @Override public Evaluation evaluate( Path path ) { String currentColor = (String) path.endNode().getProperty( "color" ); boolean endOfTheLine = path.length()+1 >= colors.length; return currentColor.equals( colors[path.length()] ) ? Evaluation.of( endOfTheLine, !endOfTheLine ) : Evaluation.EXCLUDE_AND_PRUNE; } } ).traverse( start )
I hacked up your domain just now and that traverser works out nicely!我刚刚入侵了你的域,那个遍历器运行得很好!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.