We had a little discussion about how to make a first/good implementation of
traversers in the Neo4j REST API. If we just start at the core and expose
basic traversers, as they are in the graph database API (or will be, with
the next iteration of the traversal framework finding its way into the
kernel soon) a solution like this could be handy:

   POST /node/{id}/traverse

where the entity (data you post) would be a JSON document describing the
traverser, like:

  { "order": "depth first",
    "uniquness": "node",
    "return evaluator":
       { "language": "javascript",
         "body": "function shouldReturn( pos ) {...}" },
    "prune evaluator":
       { "language": "javascript",
         "body": "function...." },
    "relationships": [
       { "direction": "outgoing",
         "type": "KNOWS" },
       { "type": "LOVES" }
    ],
    "max depth": 4 }

Where "max depth" could be a short-hand for a prune evaluator which prunes
after a certain depth, and if both "max depth" and "prune evaluator" are
specified, they are merged into one prune evaluator which checks for both
conditions. Also if nothing is supplied (an empty POST, sort of) depth 1 is
assumed, just to prevent traversing the entire graph in vain).

Looking at the "prune evaluator" and "return evaluator" it'd be nice to
define them in some language, f.ex javascript, ruby or python or whatever.
We're initially thinking of using javax.script.* stuff (ScriptEngine) for
that, it'd probably be enough, at least to get things going.


So, moving on to the result which would come back... The default would be
that nodes comes back (as an array of JSON, think an array of GET /node/{id}
data). But wait, how could I make it return relationships or paths instead?
Well, we could extend the URI (template) to:

  POST /node/{id}/traverse/{returnType}

Where returnType could be "node", "relationship" or "path" (or even
something else?).

We've happily ignored the whole paging issue which would be handy/necessary
for rather big traversals, but for an initial version I think we can do
without it.


So, how does all this feel? It'd be fun with feedback and suggestions!

-- 
Mattias Persson, [[email protected]]
Neo Technology, www.neotechnology.com
_______________________________________________
Neo mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to