[Neo4j] check for existing relationship between two nodes

Arijit Mukherjee arijit72 at gmail.com
Fri Jul 30 14:21:37 CEST 2010


Thanx Mattias. Can I download a tar.gz or zip file from somewhere? I'm
not using Maven in my projects yet...I mean I'm not very comfortable
with it.

Arijit

On 30 July 2010 17:33, Mattias Persson <mattias at neotechnology.com> wrote:
> Looping through relatiomships manually is the way to go. However
> there's a new component in
> https://svn.neo4j.org/laboratory/components/lucene-index/ which can
> index relationships and do fast lookups on whether or not a
> relationship (with a certain attribute even) exists between two nodes.
>
> You'll need to go with the latest kernel then as well (as seen in
> https://svn.neo4j.org/laboratory/components/lucene-index/pom.xml).
>
> 2010/7/30, Arijit Mukherjee <arijit72 at gmail.com>:
>> Hi All
>>
>> I have a requirement where I must check if there is an already
>> existing relationship between two nodes (say N1 and N2). Right now,
>> I'm doing it as follows:
>>
>> boolean found = false;
>> final Iterable<Relationship> currentRels =
>> N1.getRelationships(RelTypes.KNOWS, Direction.OUTGOING);
>> for (Relationship rel : currentRels) {
>>     found = rel.getEndNode().equals(N2);
>>     if (found) {
>>         do something - like add some property to the existing relationship;
>>         break;
>>     }
>> }
>> if (!found) {
>>     create new relationship between N1 and N2;
>> }
>>
>> This means, for a high volume of data, all the relations going out of
>> N1 will be retrieved and checked - and this seems costly. I'm using
>> the 1.0 API, and wasn't able to find anything that would directly
>> check whether N1 has an outgoing relationship with N2 - like
>> N1.hasRelationship(N2, Direction.OUTGOING) - or something similar. I
>> think there was a similar mail sometime ago. Has there been any
>> updates lately which allows such checks? Or, is there any other direct
>> way to do this with the 1.0 API?
>>
>> Regards
>> Arijit
>>
>> --
>> "And when the night is cloudy,
>> There is still a light that shines on me,
>> Shine on until tomorrow, let it be."
>> _______________________________________________
>> Neo4j mailing list
>> User at lists.neo4j.org
>> https://lists.neo4j.org/mailman/listinfo/user
>>
>
>
> --
> Mattias Persson, [mattias at neotechnology.com]
> Hacker, Neo Technology
> www.neotechnology.com
> _______________________________________________
> Neo4j mailing list
> User at lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
"And when the night is cloudy,
There is still a light that shines on me,
Shine on until tomorrow, let it be."


More information about the User mailing list