Skip to content

Instantly share code, notes, and snippets.

@juergenhoetzel
Created June 19, 2012 18:11
Show Gist options
  • Save juergenhoetzel/2955669 to your computer and use it in GitHub Desktop.
Save juergenhoetzel/2955669 to your computer and use it in GitHub Desktop.
Neo4J in Action (revised CustomFilteringEvaluator)
import org.neo4j.graphdb.traversal.Evaluator;
import org.neo4j.graphdb.traversal.Evaluation;
import org.neo4j.graphdb.*;
// exclude Movies seen by userNode
public class CustomFilteringEvaluator implements Evaluator {
private RelationshipType hasSeenRelationshipType = DynamicRelationshipType.withName("HAS_SEEN");
private final Node userNode;
public CustomFilteringEvaluator(Node userNode) {
this.userNode = userNode;
}
private boolean seenByUserNode(Node movieNode) {
for (Relationship r : movieNode.getRelationships(Direction.INCOMING, hasSeenRelationshipType)) {
if (r.getStartNode().equals(userNode))
return true;
}
return false;
}
public Evaluation evaluate(Path path) {
Node currentNode = path.endNode();
if (!currentNode.hasProperty("type") || !currentNode.getProperty("type").equals("Movie") || seenByUserNode (currentNode))
return Evaluation.EXCLUDE_AND_CONTINUE;
return Evaluation.INCLUDE_AND_CONTINUE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment