When I first saw this questions my reaction was "this is graph matching". Sadly our graph-matching component didn't support multiple anchor nodes. Now it does.
So one way you would do this now is: PatternNode p1 = new PatternNode(); p1.setAssociation( n1 ); PatternNode p2 = new PatternNode(); p2.setAssociation( n2 ); PatternNode p3 = new PatternNode(); p3.setAssociation( n3 ); PatternNode p4 = new PatternNode(); p4.setAssociation( n4 ); PatternNode p5 = new PatternNode(); p5.setAssociation( n5 ); PatternNode toFind = new PatternNode(); p1.createRelationshipTo( toFind ); p2.createRelationshipTo( toFind ); p3.createRelationshipTo( toFind ); p4.createRelationshipTo( toFind ); p5.createRelationshipTo( toFind ); Transaction tx = graphdb.beginTx(); try { for (PatternMatch match : PatternMatcher.getMatcher().match(p1,null,p2,p3,p4,p5)) { Node found = match.getNodeFor( toFind ); System.out.println("found matching node: " + found); } tx.success(); } finally { tx.finish(); } You would of course need to add a dependency to the latest SNAPSHOT version of graph-matching for this to work, with maven that would be: <dependency> <groupId>org.neo4j</groupId> <artifactId>neo4j-graph-matching</artifactId> <version>0.8-SNAPSHOT</version> </dependency> If you download the jar manually the latest build is here: http://m2.neo4j.org/org/neo4j/neo4j-graph-matching/0.8-SNAPSHOT/neo4j-graph-matching-0.8-20100309.140445-6.jar Cheers, Tobias On Fri, Mar 5, 2010 at 9:03 AM, Sumanth Thikka <suma...@truesparrow.com>wrote: > Hi, > > I am searching for an optimal way to find a commonly connected nodes to a > set of nodes in a graph. > > Consider the case where n1, n2, n3, n4 ,n5 are 5 nodes in a graph. These 5 > are connected to the other nodes. > I need to find the nodes in the graph which are connected all above 5 nodes > optimally. > > The solution which I can think of is like: > Find all the relationships(of a type, say KNOWS) of each of the above 5 > nodes and get to know the node with minimum relationships say n3. > For each node connected to n3, find the nodes which are connected to all > the > other four nodes. Which is our result set. > > A similar link > http://lists.neo4j.org/pipermail/user/2010-February/002722.html provided > earlier in the other thread. > From what I understood from the link, it is to know the products bought by > any of the customers who bought productX. Whereas, in my case, I need the > products which were bought by all the customers who bought product X . I am > not very sure how this solution can be extended to my case, if possible. > > Is there any other way or a graph algorithm to solve this in a more optimal > way. > > Thanks, > Sumanth > _______________________________________________ > Neo mailing list > User@lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user > -- Tobias Ivarsson <tobias.ivars...@neotechnology.com> Hacker, Neo Technology www.neotechnology.com Cellphone: +46 706 534857 _______________________________________________ Neo mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user