Can you do it on one line? ;) Great stuff.
Cheers, /peter neubauer GTalk: neubauer.peter Skype peter.neubauer Phone +46 704 106975 LinkedIn http://www.linkedin.com/in/neubauer Twitter http://twitter.com/peterneubauer http://www.neo4j.org - NOSQL for the Enterprise. http://startupbootcamp.org/ - Öresund - Innovation happens HERE. On Fri, Nov 4, 2011 at 11:12 AM, Marko Rodriguez <[email protected]> wrote: > Hi, > > I would do it like this: > > m = [:] > g.v(162).in('R_PartOf').loop(1){m.put(it.object, it.loops); true} >> -1 > m.sort{a, b -> a.value <=> b.value}.keySet as List > > In short, fill up a Map (m) with key being the vertex and value being the > number of "hops" (or times through the loop). Then sort the map by the number > of times through the loop and return the keySet. Since you wanted a List (not > a Set), then "as List" the Set result. > > HTH, > Marko. > > http://markorodriguez.com > > On Nov 4, 2011, at 10:25 AM, baldric wrote: > >> I'm very new to much of this, and have a particularly ingrained relational >> slant to my career, unfortunately. >> I'm in the process of doing a proof of concept for a product, using neo4j, >> and gremlin over REST (we're developing in c#) What I'm trying to do at the >> moment is load a graph (representing a sort of flexible taxonomy), into a >> flattened list. So, given a starting node, find all associated nodes across >> a particular relationship type, no matter how far away. I will ultimately >> need this in a list, and I want the list sorted by how far away each node is >> (am I correct in referring to this as "hops"?) >> Anyway, my best attempt at the unsorted query so far looks something like >> this: (by the way, the "unique" part worries me a little....) >> >> x = []; g.v(162).in('R_PartOf').aggregate(x).loop(2){true} >> -1; x.unique() >> >> (Please try not to laugh too much! :) ) >> >> How would I alter this to ensure it is sorted by "distance" from starting >> node? >> >> Thanks in advance! >> >> -- >> View this message in context: >> http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3480586.html >> Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. >> _______________________________________________ >> Neo4j mailing list >> [email protected] >> https://lists.neo4j.org/mailman/listinfo/user > > _______________________________________________ > Neo4j mailing list > [email protected] > https://lists.neo4j.org/mailman/listinfo/user > _______________________________________________ Neo4j mailing list [email protected] https://lists.neo4j.org/mailman/listinfo/user

