Hello,

I've been experimenting with neo4j as a replacement for a typical
relational database in an application I'm working on.  The object
graph I have has a relationship path like

Customer ---- customer ordered ----> Order ----> order includes ---->
Item ----> of type ----> Type

There are other relationships, but this is the one I'm interested in
finding out about at the moment.  What I want to be able to do is find
all the customers that have ordered items of a specific type.  I
looked at the traverser API and you can find last relationship
traversed, but is there a way to find the path that was traversed?
One solution might be to start with the type node(s) and find any
customer nodes?  But, if there is an additional relationship like

Customer ----> interested in -----> Type

I'm not sure that would work.  I suppose I could also do a the
traversal a bit more manually like

for (Relationship orderedRel : customerNode.getRelationships(ORDERED)) {
    for (Relationship includesRel :
orderedRel.getEndNode().getRelationships(INCLUDED)) {
        for (Relationship typeRel :
includesRel.getEndNode().getRelationships(OF_TYPE)) {
            if (typeRel.getProperty("name").equals(searchType)) {
                customersWhoBought.add(orderedRel.getEndNode());
            }
        }
    }
}

But that seems inefficient.  Is there a better way?

Thanks,
Rich
_______________________________________________
Neo mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to