[Neo4j] check for existing relationship between two nodes

Jeff Klann jklann at iupui.edu
Mon Aug 16 22:50:48 CEST 2010


Hey I thought I'd try this out. Got the new kernel and downloaded the new
index component snapshot but can't figure out how to use it. Perhaps I'm
just dense. Looks like the only class in the Javadoc is an abstract class so
I don't know how to instantiate a new relationship index. Have an example?

Thanks,
Jeff Klann

On Fri, Jul 30, 2010 at 10:19 AM, Mattias Persson <mattias at neotechnology.com
> wrote:

> The latest snapshots of things can be found at http://m2.neo4j.org/
> and this component (jar-file) can be found in
> http://m2.neo4j.org/org/neo4j/neo4j-lucene-index/0.1-SNAPSHOT/
>
> 2010/7/30, Arijit Mukherjee <arijit72 at gmail.com>:
> > 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."
> > _______________________________________________
> > 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
>


More information about the User mailing list