Created
April 1, 2012 18:58
-
-
Save FaKod/2277743 to your computer and use it in GitHub Desktop.
Neo4j Typed Traverser Examples using the REST interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
{ | |
/** | |
* follow list of nodes with relations BOTH "KNOWS" and OUT "CODED_BY" | |
*/ | |
val erg = startNodes.doTraverse[Test_MatrixBase](follow -- "KNOWS" ->- "CODED_BY") { | |
/** | |
* prune evaluator is Java Script and returns false | |
*/ | |
PruneEvaluator("false") | |
} { | |
/** | |
* Return filter (running on client side) | |
*/ | |
case (x: Test_Matrix, tp) if (tp.depth == 3) => x.name.length > 2 | |
case (x: Test_NonMatrix, _) => false | |
/** | |
* converted to List[Test_MatrixBase] | |
*/ | |
}.toList.sortWith(_.name < _.name) | |
} | |
{ | |
val erg = nodeMap("Neo").doTraverse[Test_MatrixBase](follow(BREADTH_FIRST) -- "KNOWS" ->- "CODED_BY" -<- "FOO") { | |
/** | |
* using prune eval as Java Script code | |
*/ | |
"position.length() > 100;" | |
} { | |
case (x: Test_Matrix, tp) if (tp.depth == 2) => x.name.length > 2 | |
case (x: Test_NonMatrix, _) => false | |
}.toList.sortWith(_.name < _.name) | |
} | |
{ | |
/** | |
* setting max depth to 100 instead of prune evaluator | |
*/ | |
val erg = nodeMap("Neo").doTraverse[Test_MatrixBase](follow(BREADTH_FIRST) -- "KNOWS" ->- "CODED_BY")(100) { | |
case (x: Test_Matrix, tp) if (tp.depth == 2) => x.name.length > 2 | |
}.toList.sortWith(_.name < _.name) | |
} | |
{ | |
/** | |
* set max depth to 1 and using builtin ReturnAllButStartNode function | |
*/ | |
val erg = nodeMap("Neo"). | |
doTraverse[Test_MatrixBase](follow(BREADTH_FIRST) -- "KNOWS" ->- "CODED_BY", 1, ReturnAllButStartNode). | |
toList.sortWith(_.name < _.name) | |
} | |
{ | |
/** | |
* set max depth to 1 and using Java Script "true" code | |
*/ | |
val erg = nodeMap("Neo"). | |
doTraverse[Test_MatrixBase](follow(BREADTH_FIRST) -- "KNOWS" ->- "CODED_BY", 1, "true"). | |
toList.sortWith(_.name < _.name) | |
} | |
{ | |
/** | |
* server side type check with endNode.isOfType[Test_Matrix] that created Java Script code | |
*/ | |
val erg = nodeMap("Neo").doTraverse[Test_MatrixBase](follow(BREADTH_FIRST) -- "KNOWS" ->- "CODED_BY", 1, | |
endNode.instanceof[Test_Matrix] | |
).toList.sortWith(_.name < _.name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment