Hi Mattias,
Thank you very much for you quick answer ! :)
In fact, I tried your solution.
Here is a code snippet with just a few nodes (only one distinct "object
graph" in it) :
public void testTraversing() {
Transaction tx = neo.beginTx();
Node world;
Node n1;
try {
world = neo.createNode();
world.setProperty("name", "world");
n1 = neo.createNode();
n1.setProperty("name", "n1");
Node n2 = neo.createNode();
n2.setProperty("name", "n2");
Node n3 = neo.createNode();
n3.setProperty("name", "n3");
Node n4 = neo.createNode();
n4.setProperty("name", "n4");
Relationship relationship;
relationship = world.createRelationshipTo(n1,
MyRelationshipTypes.CONTAINS);
relationship.setProperty("beginDateOffset", 0);
relationship.setProperty("endDateOffset", Integer.MAX_VALUE);
relationship = world.createRelationshipTo(n2,
MyRelationshipTypes.CONTAINS);
relationship.setProperty("beginDateOffset", 0);
relationship.setProperty("endDateOffset", Integer.MAX_VALUE);
relationship = world.createRelationshipTo(n3,
MyRelationshipTypes.CONTAINS);
relationship.setProperty("beginDateOffset", 0);
relationship.setProperty("endDateOffset", Integer.MAX_VALUE);
relationship = world.createRelationshipTo(n4,
MyRelationshipTypes.CONTAINS);
relationship.setProperty("beginDateOffset", 0);
relationship.setProperty("endDateOffset", Integer.MAX_VALUE);
relationship = n1.createRelationshipTo(n2,
MyRelationshipTypes.KNOWS);
relationship.setProperty("beginDateOffset", 2);
relationship.setProperty("endDateOffset", 10);
relationship = n2.createRelationshipTo(n3,
MyRelationshipTypes.KNOWS);
relationship.setProperty("beginDateOffset", 1);
relationship.setProperty("endDateOffset", 10);
relationship = n2.createRelationshipTo(n4,
MyRelationshipTypes.KNOWS);
relationship.setProperty("beginDateOffset", 3);
relationship.setProperty("endDateOffset", 5);
tx.success();
} finally {
tx.finish();
}
// now search !
// test fetching only nodes with a startDate after date 3
Traverser friendsTraverser = world.traverse(
Traverser.Order.DEPTH_FIRST,
StopEvaluator.END_OF_GRAPH,
new ReturnableEvaluator() {
public boolean isReturnableNode(TraversalPosition pos) {
if (pos.lastRelationshipTraversed() != null) {
if
(pos.lastRelationshipTraversed().isType(MyRelationshipTypes.KNOWS)) {
if (((Integer)
pos.lastRelationshipTraversed().getProperty("beginDateOffset")) >= 3) {
return true;
}else{
return false;
}
} else {
return false;
}
} else {
return false;
}
}
},
MyRelationshipTypes.CONTAINS,
Direction.OUTGOING,
MyRelationshipTypes.KNOWS,
Direction.OUTGOING);
for (Node object : friendsTraverser) {
System.out.println(" next node : " +
object.getProperty("name"));
}
}
For me, the code should :
- start from world node (my root node)
- follow CONTAINS and KNOWS links (the two link type in the graph)
- return a node only if this node has an incoming link with a
beginDateOffset property > 3
With this code, I never get any system.out.
Is there something I completely get wrong ?
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 31 Jul 2009 10:50:24 +0200
> From: Mattias Persson <[email protected]>
> Subject: Re: [Neo] Searching 'links', based on their attributes ?
> To: Neo user discussions <[email protected]>
> Message-ID:
> <[email protected]>
> Content-Type: text/plain; charset=UTF-8
>
> Hi Sebastian,
>
> I'm not sure I really grasp your problem, but one solution that seems
> appropriate would be to connect all those object graphs to one "super
> root node" of your choice. So that you create this super root node,
> maybe connect it to the neo reference node and let all your object
> graphs have some relationship to that super root node. That way
> they'll all be connected in a way and you could have that node as a
> starting node when you traverse.
>
> Alternatively you could connect all your object graphs to the neo
> reference node directly and use that as a starting point for your
> traversals.
>
> Would that help you?
>
> 2009/7/31 sebastien nichele <[email protected]>:
> > Hi,
> >
> > I'm currently evaluating neo4j and I'am really satisfied/impressed by it.
> >
> > However, I'm asking myself several questions.
> >
> > In my "node space" I have several dissocied objects graphs.
> > Links between nodes bears two attributes "startDate" and "endDate".
> >
> > ?At one time, i want to display all nodes in my graph that have links
> > ?that match some combinations of startDate and endDate (ie. 'give me all
> > nodes linked by links that
> > ?have dates between 1st january and 3 march'), whatever the link nature
> is.
> >
> > ?I started using traversing for that, using exemples I found on
> > documentation.
> > ?My problem is that I don't have any "super root node" in my "node space"
> to
> > start traversing (since traversing needs a 'root' node), but several
> graphs
> > with several root nodes.
> >
> > ?In realize that in fact, I don't really want to "traverse" a graph, but
> > simply pick links based on their attributes, and then, return nodes on
> links
> > sides.
> >
> > ?I digged upon the documentation, but didn't find a way to do that simply
> > and efficiently.
> >
> > ?I have the feeling that I am missing something...
> >
> > ?Can anyone shed some light on my matter ? ;)
> >
> > ?Thanks in advance for your answers,
> >
> > ?Best regards,
> >
> > ?sni.
> > _______________________________________________
> > Neo mailing list
> > [email protected]
> > https://lists.neo4j.org/mailman/listinfo/user
> >
>
>
>
> --
> Mattias Persson, [[email protected]]
> Neo Technology, www.neotechnology.com
>
>
> ------------------------------
>
> _______________________________________________
> User mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
>
>
> End of User Digest, Vol 28, Issue 35
> ************************************
>
_______________________________________________
Neo mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user