Re: [Neo] Searching 'links', based on their attributes ? [SOLUTION]

2009-08-01 Thread Mattias Persson
Allright I think the reason you aren't getting any answers is that a
traverser doesn't visit the same node twice during its lifetime. So if
the traverser is traversing from world to n3 it won't follow the
KNOWS relationship to n2 since you specified only OUTGOING such
relationship in the traverser. Then the traverser may come to the n2
node and wont go via KNOWS to the n3 node since it has already been
there.

Another solution would be to create one traverser for each object graph like:

for ( Relationship graphRelationship : world.getRelationships(
MyRelationshipTypes.CONTAINS, Direction.OUTGOING ) )
{
Traverser traverser = graphRelationship.getEndNode().traverse(
Traverser.Order.DEPTH_FIRST,

}


And, yeah, it's generally not a good idea to iterate over a nodes
every relationship... could be a performance problem if the graph
grows.

2009/7/31 sebastien nichele snich...@sqli.com:
 Mattias,

 Ok well, after a little bit of greymatter work, I finally got it.

 I didn't realized that links provides reachability of the nodes, not
 filtering of the nodes.

 Since all nodes are linked to a root node, i can reach all nodes by
 traversing from rootnode only on CONTAINS links.
 I have then to filter nodes depending on interesting attributes...

 The following code does what I want.

        final int sOffset = 3;
        Traverser friendsTraverser = world.traverse(
                Traverser.Order.BREADTH_FIRST,
                StopEvaluator.END_OF_GRAPH,
                new ReturnableEvaluator() {
                    public boolean isReturnableNode(TraversalPosition pos) {

                        boolean atLeastAnIncomingKnowsBoundedLink = false;
                        boolean atLeastAnOutgoingKnowsBoundedLink = false;

                        Iterator allOutRels =
 pos.currentNode().getRelationships(Direction.OUTGOING).iterator();

                        while (allOutRels.hasNext()) {
                            Relationship object = (Relationship)
 allOutRels.next();

 if(((Integer)object.getProperty(beginDateOffset)) = sOffset){
                                    atLeastAnOutgoingKnowsBoundedLink |=
 true;
                                }
                        }
                        Iterator allInRels =
 pos.currentNode().getRelationships(Direction.INCOMING).iterator();
                        while (allInRels.hasNext()) {
                            Relationship object = (Relationship)
 allInRels.next();

 if(((Integer)object.getProperty(beginDateOffset)) = sOffset){
                                    atLeastAnIncomingKnowsBoundedLink |=
 true;
                                }
                        }

                        return atLeastAnIncomingKnowsBoundedLink ||
 atLeastAnOutgoingKnowsBoundedLink;
                    }
                },
                MyRelationshipTypes.CONTAINS,
                Direction.OUTGOING);

 Since I can reach all nodes with CONTAINS link type, I doesn't need to
 'traverse' the other type like I've naively done before.

 I tried various values for the links properties, and the result is OK !

 On top of that, I would add a subsidiary question : is my solution not
 performance killer ? Iterating through all incoming and outgoing links from
 a node is not overkill ?

 Thank you in advance,

 Best regards,

 sni.





 2009/7/31 user-requ...@lists.neo4j.org

 Send User mailing list submissions to
        u...@lists.neo4j.org

 To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.neo4j.org/mailman/listinfo/user
 or, via email, send a message with subject or body 'help' to
        user-requ...@lists.neo4j.org

 You can reach the person managing the list at
        user-ow...@lists.neo4j.org

 When replying, please edit your Subject line so it is more specific
 than Re: Contents of User digest...


 Today's Topics:

   1. Re: Searching 'links', based on their attributes ?
      (Mattias Persson)


 --

 Message: 1
 Date: Fri, 31 Jul 2009 10:50:24 +0200
 From: Mattias Persson matt...@neotechnology.com
 Subject: Re: [Neo] Searching 'links', based on their attributes ?
 To: Neo user discussions user@lists.neo4j.org
 Message-ID:
        acdd47330907310150q19969efgae877de00d783...@mail.gmail.com
 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 

Re: [Neo] Searching 'links', based on their attributes ? [SOLUTION]

2009-07-31 Thread sebastien nichele
Mattias,

Ok well, after a little bit of greymatter work, I finally got it.

I didn't realized that links provides reachability of the nodes, not
filtering of the nodes.

Since all nodes are linked to a root node, i can reach all nodes by
traversing from rootnode only on CONTAINS links.
I have then to filter nodes depending on interesting attributes...

The following code does what I want.

final int sOffset = 3;
Traverser friendsTraverser = world.traverse(
Traverser.Order.BREADTH_FIRST,
StopEvaluator.END_OF_GRAPH,
new ReturnableEvaluator() {
public boolean isReturnableNode(TraversalPosition pos) {

boolean atLeastAnIncomingKnowsBoundedLink = false;
boolean atLeastAnOutgoingKnowsBoundedLink = false;

Iterator allOutRels =
pos.currentNode().getRelationships(Direction.OUTGOING).iterator();

while (allOutRels.hasNext()) {
Relationship object = (Relationship)
allOutRels.next();

if(((Integer)object.getProperty(beginDateOffset)) = sOffset){
atLeastAnOutgoingKnowsBoundedLink |=
true;
}
}
Iterator allInRels =
pos.currentNode().getRelationships(Direction.INCOMING).iterator();
while (allInRels.hasNext()) {
Relationship object = (Relationship)
allInRels.next();

if(((Integer)object.getProperty(beginDateOffset)) = sOffset){
atLeastAnIncomingKnowsBoundedLink |=
true;
}
}

return atLeastAnIncomingKnowsBoundedLink ||
atLeastAnOutgoingKnowsBoundedLink;
}
},
MyRelationshipTypes.CONTAINS,
Direction.OUTGOING);

Since I can reach all nodes with CONTAINS link type, I doesn't need to
'traverse' the other type like I've naively done before.

I tried various values for the links properties, and the result is OK !

On top of that, I would add a subsidiary question : is my solution not
performance killer ? Iterating through all incoming and outgoing links from
a node is not overkill ?

Thank you in advance,

Best regards,

sni.





2009/7/31 user-requ...@lists.neo4j.org

 Send User mailing list submissions to
user@lists.neo4j.org

 To subscribe or unsubscribe via the World Wide Web, visit
https://lists.neo4j.org/mailman/listinfo/user
 or, via email, send a message with subject or body 'help' to
user-requ...@lists.neo4j.org

 You can reach the person managing the list at
user-ow...@lists.neo4j.org

 When replying, please edit your Subject line so it is more specific
 than Re: Contents of User digest...


 Today's Topics:

   1. Re: Searching 'links', based on their attributes ?
  (Mattias Persson)


 --

 Message: 1
 Date: Fri, 31 Jul 2009 10:50:24 +0200
 From: Mattias Persson matt...@neotechnology.com
 Subject: Re: [Neo] Searching 'links', based on their attributes ?
 To: Neo user discussions user@lists.neo4j.org
 Message-ID:
acdd47330907310150q19969efgae877de00d783...@mail.gmail.com
 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 snich...@sqli.com:
  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