[Neo4j] retrieve all relationships of a certain type (java)

2011-07-20 Thread cyuczi eekc
How would I go about retrieving all nodes for a certain relationship Type
(ie. assuming I don't know any of them nodes) ? (in java code, the other
variants rest/cypher I will probably not need to use)
ie. rel.getAllNodes(Direction.INCOMING)
or rel.getAllNodes(Direction.OUTGOING)
or Direction.BOTH even
 But this is basically equivalent with retrieving all relationships that are
of the specified relationship-type. So this would be more accurate:
rel.getAllRelationships(); where rel is the Relationship of the type that we
want and the getAllRelationships() would return something that would be a
list of all relationship of that type (in the entire database I guess)

but possibly _*without*_ having to iterate (or traverse?) all nodes(i guess
starting from the reference node?), in order to find if each has the
relationship type I'm looking for. (I haven't yet fully looked at traverse
but I know it needs a starting node, even though this could probably be the
reference node[?]; this makes me wonder if there's a traverser for
relationships instead of just nodes - I am unsure where to look [maybe just
pointing me there would be enough of a reply to this; thanks])

The way I see it, the fact that relationships have a type  is an extra layer
on top of the relationships (just as indexing is extra(independent) layer on
top of nodes or relationships). So I see the relationships each being unique
(especially since I can add the same-type relationship to the same two
nodes, more than 1 time) and they are somehow coalesced together via the
relationship-type. It's like the relationship-type is a set which contains a
bunch of relationships (which are obviously unique ie. unique ID) and this
set constitutes a relationship-type. So since it's a set (probably stored as
key-value pairs on the low level) one could potentially just get the
elements via an iterator or something (but I also want to know how many aka
size or count, relationships are there, of this type). (what I find a bit
odd though, is that you can have more than one relationship for the same two
nodes (1: A-B ; 2: A-B ), although dwins(on irc) implied that this is
allowed because each relationship can have key-value pairs(properties)
associated with it, and thus one could use same key for each relationship
but with different values, but the practicality for this escapes me)
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] retrieve all relationships of a certain type (java)

2011-07-20 Thread Marko Rodriguez
Hey,

 How would I go about retrieving all nodes for a certain relationship Type
 (ie. assuming I don't know any of them nodes) ?


Use an index. I don't know in native Neo4j off the top of my head, but the 
analogous to this in Blueprints:

g.getIndex(edges, Edge.class).get(label,myType)

Indices allow you to group edges of similar label together.

See ya,
Marko.

http://markorodriguez.com

On Jul 20, 2011, at 12:54 PM, cyuczi eekc wrote:

 (in java code, the other
 variants rest/cypher I will probably not need to use)
 ie. rel.getAllNodes(Direction.INCOMING)
 or rel.getAllNodes(Direction.OUTGOING)
 or Direction.BOTH even
 But this is basically equivalent with retrieving all relationships that are
 of the specified relationship-type. So this would be more accurate:
 rel.getAllRelationships(); where rel is the Relationship of the type that we
 want and the getAllRelationships() would return something that would be a
 list of all relationship of that type (in the entire database I guess)
 
 but possibly _*without*_ having to iterate (or traverse?) all nodes(i guess
 starting from the reference node?), in order to find if each has the
 relationship type I'm looking for. (I haven't yet fully looked at traverse
 but I know it needs a starting node, even though this could probably be the
 reference node[?]; this makes me wonder if there's a traverser for
 relationships instead of just nodes - I am unsure where to look [maybe just
 pointing me there would be enough of a reply to this; thanks])
 
 The way I see it, the fact that relationships have a type  is an extra layer
 on top of the relationships (just as indexing is extra(independent) layer on
 top of nodes or relationships). So I see the relationships each being unique
 (especially since I can add the same-type relationship to the same two
 nodes, more than 1 time) and they are somehow coalesced together via the
 relationship-type. It's like the relationship-type is a set which contains a
 bunch of relationships (which are obviously unique ie. unique ID) and this
 set constitutes a relationship-type. So since it's a set (probably stored as
 key-value pairs on the low level) one could potentially just get the
 elements via an iterator or something (but I also want to know how many aka
 size or count, relationships are there, of this type). (what I find a bit
 odd though, is that you can have more than one relationship for the same two
 nodes (1: A-B ; 2: A-B ), although dwins(on irc) implied that this is
 allowed because each relationship can have key-value pairs(properties)
 associated with it, and thus one could use same key for each relationship
 but with different values, but the practicality for this escapes me)
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user