>
> Hmmmm...

> I am guessing the most efficient way might be to have a two stage return

evaluator.


> E.g. The custom return evaluator class has a hash table of <node id> =>

<count> pairs. Each time 'isReturnableNode' is called, it increments the

count for that node id in the hash. If count >= <total number of tags to

check for> return the node.


> Thus, if you run a traversal starting from each tag using the same instance

of the custom return evaluator, none of the traversals will emit any nodes

(good for memory!) until the last one, where the ones matching all the tags

will be emitted.


> Does that sound like it would work?



I wrote a n-stages return evaluator and its works fine.

MainClass.java

public class MainClass {


> public static void main(String[] args) {

GraphDatabaseService graphDb = new
> EmbeddedReadOnlyGraphDatabase("/path/to/db");

Transaction tx = graphDb.beginTx();

try {

Node node1 = graphDb.getNodeById(1);

Node node3 = graphDb.getNodeById(3);


> NStepsReturnEvaluator steps = new NStepsReturnEvaluator();


> Traverser t1 = node1.traverse(Order.DEPTH_FIRST,

StopEvaluator.END_OF_GRAPH, steps.setStep(ReturnableEvaluator.ALL),

Direction.OUTGOING);

 Traverser t3 = node3.traverse(Order.DEPTH_FIRST,

StopEvaluator.END_OF_GRAPH, steps.setStep(ReturnableEvaluator.ALL),

Direction.OUTGOING);


> t1.getAllNodes();

for (Node node : t3) {

System.out.println(node.getId());

}


> } finally {

tx.finish();

}

System.exit(0);

}

}


NStepsReturnEvaluator.java

 class NStepsReturnEvaluator implements ReturnableEvaluator {


> private Hashtable<Node, Long> stepNodes = new Hashtable<Node, Long>();


> private ReturnableEvaluator step;


> private long stepCount = 0;


> public ReturnableEvaluator setStep(ReturnableEvaluator step) {

stepCount++;

this.step = step;

return this;

}


> @Override

public boolean isReturnableNode(TraversalPosition currentPos) {

if (step.isReturnableNode(currentPos)) {

Node currentNode = currentPos.currentNode();

if (stepNodes.isEmpty()) {

stepNodes.put(currentNode, 1L);

return true;

} else {

Long count = stepNodes.get(currentNode);

count = 1 + (count != null ? count : 0);

stepNodes.put(currentNode, count);

if (count >= stepCount) {

return true;

}

}

}

return false;

}

}
_______________________________________________
Neo mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to