Hi! Johan Svensson skrev:
One way would be to do a traversal from the "word-node" with the least number for relationships.
OK, I implemented this. But I *do* have to iterate over the relationships to get the count?
At the moment I only want the search to return one best match: either the first that matches all search words or the one matching as many words as possible (this alternative is a bit simplistic as I start the traversal from one point only).
I attached some screenshots from my current IMDB node space. I tried two different ways performing the traversal: 1. traverser framework 2. nested loops Both do have their pros and cons, I think. Any suggestions for improvements on the code? Wich one would you choose?! /anders // use a traverser Traverser traverser = startNode.traverse( Order.DEPTH_FIRST, new StopEvaluator() { public boolean isStopNode( TraversalPosition currentPos ) { return currentPos.depth() >= 2; } }, ReturnableEvaluator.ALL_BUT_START_NODE, wordRelType, Direction.BOTH ); Node currentBase = null; int count = 0; for ( Node node : traverser ) { if ( traverser.currentPosition().depth() == 1 ) { currentBase = node; count = 0; } else if ( wordList.contains( node ) ) { count++; if ( count == listSize ) { return currentBase; } if ( count > highscore ) { bestMatch = currentBase; highscore = count; } } } // loop over relationships for ( Relationship rel : startNode.getRelationships( wordRelType ) ) { Node node = rel.getEndNode(); int count = 0; for ( Relationship innerRel : node.getRelationships( wordRelType ) ) { if ( wordList.contains( innerRel.getStartNode() ) ) { count++; if ( count == listSize ) { return node; } } } if ( count > highscore ) { bestMatch = node; highscore = count; } }
<<inline: 1.png>>
<<inline: 2.png>>
<<inline: 3.png>>
<<inline: 4.png>>
_______________________________________________ Neo mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user