Re: [Neo4j] Node.hasRelationship question

2010-10-28 Thread Mattias Persson
2010/10/28 Walaa Eldin Moustafa wa.moust...@gmail.com

 Hi Mattias,

 Even if I pass nulls, I will still have to build an index on some key
 (property). I do not want to do that because it adds the property
 index overhead for something that I am not actually using.


I think it's definately worth that tiny extra overhead since lookups are
very fast (no looping at all, but instead direct index lookups).



 By the way, does the underlying code for index.get(kay, value, start,
 end) iterate over all the relationships of start and checks if one is
 connected to end, or it does perform a direct look up to get the edges
 between (start, end)?


No looping, just a direct lookup. Maybe RelationshipIndex should have a
method:

add( Relationship relationship );

which indexes that relationship (with its start/end node as usual) but w/o
any additional property. Would that be a good idea?



 Thanks.


 On Wed, Oct 27, 2010 at 4:50 PM, Mattias Persson
 matt...@neotechnology.com wrote:
  2010/10/27, Walaa Eldin Moustafa wa.moust...@gmail.com:
  I am looking for a method that is if given a node n1, can answer the
  query if n1 has a relationship of type t with node n2, something along
  the lines of:
 
  boolean b = n1.hasRelatioship(n2,t);
 
  I know we can answer this question by iterating over n1's
  getRelationships() and testing them. However, I was looking for
  something more efficient that does not have to iterate over the node's
  relationships, especially that I noticed that the RelationshipIndex
  interface has a get() method that does something like that; however we
  have to supply it with a key and a value for an attribute for the edge
  between the two nodes. So I was looking for something like this
  method, but without having to pass a key/value pair.
 
  you can actually leave out key/value (pass in null) if you pass in
  start/end node, or you can index the relationship type as a key/value
  pair for each relationship and then do: get( type, knows, person1,
  person2 );
 
  would that help?
  ___
  Neo4j mailing list
  User@lists.neo4j.org
  https://lists.neo4j.org/mailman/listinfo/user
 
 
 
  --
  Mattias Persson, [matt...@neotechnology.com]
  Hacker, Neo Technology
  www.neotechnology.com
  ___
  Neo4j mailing list
  User@lists.neo4j.org
  https://lists.neo4j.org/mailman/listinfo/user
 
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user




-- 
Mattias Persson, [matt...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Node.hasRelationship question

2010-10-28 Thread Francois Kassis
I already used the regular index to lookup for existing relationships as 
workaround. it's definitely faster then looping specially when database is 
growing.
it will be really useful to have an index for relationships.

--
From: Mattias Persson matt...@neotechnology.com
Sent: Thursday, October 28, 2010 10:48 AM
To: Neo4j user discussions user@lists.neo4j.org
Subject: Re: [Neo4j] Node.hasRelationship question

 2010/10/28 Walaa Eldin Moustafa wa.moust...@gmail.com

 Hi Mattias,

 Even if I pass nulls, I will still have to build an index on some key
 (property). I do not want to do that because it adds the property
 index overhead for something that I am not actually using.


 I think it's definately worth that tiny extra overhead since lookups are
 very fast (no looping at all, but instead direct index lookups).



 By the way, does the underlying code for index.get(kay, value, start,
 end) iterate over all the relationships of start and checks if one is
 connected to end, or it does perform a direct look up to get the edges
 between (start, end)?


 No looping, just a direct lookup. Maybe RelationshipIndex should have a
 method:

add( Relationship relationship );

 which indexes that relationship (with its start/end node as usual) but w/o
 any additional property. Would that be a good idea?



 Thanks.


 On Wed, Oct 27, 2010 at 4:50 PM, Mattias Persson
 matt...@neotechnology.com wrote:
  2010/10/27, Walaa Eldin Moustafa wa.moust...@gmail.com:
  I am looking for a method that is if given a node n1, can answer the
  query if n1 has a relationship of type t with node n2, something along
  the lines of:
 
  boolean b = n1.hasRelatioship(n2,t);
 
  I know we can answer this question by iterating over n1's
  getRelationships() and testing them. However, I was looking for
  something more efficient that does not have to iterate over the node's
  relationships, especially that I noticed that the RelationshipIndex
  interface has a get() method that does something like that; however we
  have to supply it with a key and a value for an attribute for the edge
  between the two nodes. So I was looking for something like this
  method, but without having to pass a key/value pair.
 
  you can actually leave out key/value (pass in null) if you pass in
  start/end node, or you can index the relationship type as a key/value
  pair for each relationship and then do: get( type, knows, person1,
  person2 );
 
  would that help?
  ___
  Neo4j mailing list
  User@lists.neo4j.org
  https://lists.neo4j.org/mailman/listinfo/user
 
 
 
  --
  Mattias Persson, [matt...@neotechnology.com]
  Hacker, Neo Technology
  www.neotechnology.com
  ___
  Neo4j mailing list
  User@lists.neo4j.org
  https://lists.neo4j.org/mailman/listinfo/user
 
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user




 -- 
 Mattias Persson, [matt...@neotechnology.com]
 Hacker, Neo Technology
 www.neotechnology.com
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user
 
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Node.hasRelationship question

2010-10-28 Thread Walaa Eldin Moustafa
 By the way, does the underlying code for index.get(kay, value, start,
 end) iterate over all the relationships of start and checks if one is
 connected to end, or it does perform a direct look up to get the edges
 between (start, end)?


 No looping, just a direct lookup. Maybe RelationshipIndex should have a
 method:

    add( Relationship relationship );

 which indexes that relationship (with its start/end node as usual) but w/o
 any additional property. Would that be a good idea?


Yes, definitely that is a very good idea.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Node.hasRelationship question

2010-10-27 Thread Marko Rodriguez
Hi,

You could try Gremlin -- http://gremlin.tinkerpop.com ...

g:count($n1/ou...@label='t']/i...@id=$n2_id)  0

It will iterate over all out edges of n1, but, you will find more flexibility 
in determining if particular paths exist. That is, if you plan more complicated 
expressions. 

If you are doing this from within Java, see:
http://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through-Java

Good luck,
Marko.

http://markorodriguez.com

On Oct 27, 2010, at 2:09 PM, Walaa Eldin Moustafa wrote:

 I am looking for a method that is if given a node n1, can answer the
 query if n1 has a relationship of type t with node n2, something along
 the lines of:
 
 boolean b = n1.hasRelatioship(n2,t);
 
 I know we can answer this question by iterating over n1's
 getRelationships() and testing them. However, I was looking for
 something more efficient that does not have to iterate over the node's
 relationships, especially that I noticed that the RelationshipIndex
 interface has a get() method that does something like that; however we
 have to supply it with a key and a value for an attribute for the edge
 between the two nodes. So I was looking for something like this
 method, but without having to pass a key/value pair.
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Node.hasRelationship question

2010-10-27 Thread Mattias Persson
2010/10/27, Walaa Eldin Moustafa wa.moust...@gmail.com:
 I am looking for a method that is if given a node n1, can answer the
 query if n1 has a relationship of type t with node n2, something along
 the lines of:

 boolean b = n1.hasRelatioship(n2,t);

 I know we can answer this question by iterating over n1's
 getRelationships() and testing them. However, I was looking for
 something more efficient that does not have to iterate over the node's
 relationships, especially that I noticed that the RelationshipIndex
 interface has a get() method that does something like that; however we
 have to supply it with a key and a value for an attribute for the edge
 between the two nodes. So I was looking for something like this
 method, but without having to pass a key/value pair.

you can actually leave out key/value (pass in null) if you pass in
start/end node, or you can index the relationship type as a key/value
pair for each relationship and then do: get( type, knows, person1,
person2 );

would that help?
___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user



-- 
Mattias Persson, [matt...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Node.hasRelationship question

2010-10-27 Thread Walaa Eldin Moustafa
Thanks Marko. I was actually referring to something more efficient
than iterating over all the nodes. Gremlin is something that I
definitely want to try, but not for that project.


On Wed, Oct 27, 2010 at 4:16 PM, Marko Rodriguez okramma...@gmail.com wrote:
 Hi,

 You could try Gremlin -- http://gremlin.tinkerpop.com ...

        g:count($n1/ou...@label='t']/i...@id=$n2_id)  0

 It will iterate over all out edges of n1, but, you will find more flexibility 
 in determining if particular paths exist. That is, if you plan more 
 complicated expressions.

 If you are doing this from within Java, see:
        http://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through-Java

 Good luck,
 Marko.

 http://markorodriguez.com

 On Oct 27, 2010, at 2:09 PM, Walaa Eldin Moustafa wrote:

 I am looking for a method that is if given a node n1, can answer the
 query if n1 has a relationship of type t with node n2, something along
 the lines of:

 boolean b = n1.hasRelatioship(n2,t);

 I know we can answer this question by iterating over n1's
 getRelationships() and testing them. However, I was looking for
 something more efficient that does not have to iterate over the node's
 relationships, especially that I noticed that the RelationshipIndex
 interface has a get() method that does something like that; however we
 have to supply it with a key and a value for an attribute for the edge
 between the two nodes. So I was looking for something like this
 method, but without having to pass a key/value pair.
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user

 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Node.hasRelationship question

2010-10-27 Thread Walaa Eldin Moustafa
Hi Mattias,

Even if I pass nulls, I will still have to build an index on some key
(property). I do not want to do that because it adds the property
index overhead for something that I am not actually using.

By the way, does the underlying code for index.get(kay, value, start,
end) iterate over all the relationships of start and checks if one is
connected to end, or it does perform a direct look up to get the edges
between (start, end)?

Thanks.


On Wed, Oct 27, 2010 at 4:50 PM, Mattias Persson
matt...@neotechnology.com wrote:
 2010/10/27, Walaa Eldin Moustafa wa.moust...@gmail.com:
 I am looking for a method that is if given a node n1, can answer the
 query if n1 has a relationship of type t with node n2, something along
 the lines of:

 boolean b = n1.hasRelatioship(n2,t);

 I know we can answer this question by iterating over n1's
 getRelationships() and testing them. However, I was looking for
 something more efficient that does not have to iterate over the node's
 relationships, especially that I noticed that the RelationshipIndex
 interface has a get() method that does something like that; however we
 have to supply it with a key and a value for an attribute for the edge
 between the two nodes. So I was looking for something like this
 method, but without having to pass a key/value pair.

 you can actually leave out key/value (pass in null) if you pass in
 start/end node, or you can index the relationship type as a key/value
 pair for each relationship and then do: get( type, knows, person1,
 person2 );

 would that help?
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user



 --
 Mattias Persson, [matt...@neotechnology.com]
 Hacker, Neo Technology
 www.neotechnology.com
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user