Hopefully someone has a better way, but as I've been running into
bottlenecks like this, I've been adding node properties. As in, if there's a
single relationship (that you care about) with edge id 33 between nodes 1
and 2, I'd add a property "edge" to node 1 that's the array [2,33] and
vice-versa for node 2. This totally breaks the graphness and treats it more
like an object db but with some wrapper code it's not too much of a hassle.

Better might be the edge indexer like you mentioned, or long-term I wonder
if Neo4j will support hypergraphs? That's an instance where it'd be useful,
I think. You could have a "list root" node pointing to all the edges you
care about and only iterate through those.

But those aren't short term solutions. Does someone have a better one? I'd
learn from it too. :)

- Jeff Klann

On Thu, Sep 2, 2010 at 1:23 PM, Paul A. Jackson <[email protected]> wrote:

> I'm looking for an efficient way to find an (the) edge(s) between two
> nodes.
>
> I have a requirement that when I add an edge between two specific nodes
> that I first determine if the edge already exists, which leads to the need
> for a method that return such an edge given the subject and object.  Since I
> was unable to find such a method I attempted to create my own, which worked,
> but has become the performance bottleneck in the code.
>  private Relationship getSingeRelationship(Node subject, Node object,
> RelationshipType relationshipType, String key)
>  {
>    for (Relationship relationship : getCommonRelationships(subject, object,
> relationshipType, Direction.OUTGOING))
>    {
>      boolean currentHasIndex = relationship.hasProperty(EDGE_INDEX_KEY);
>      if (key == null)
>      {
>        if (!currentHasIndex)
>        {
>          return relationship;
>        }
>      }
>      else
>      {
>        if (currentHasIndex &&
> key.equals(relationship.getProperty(EDGE_INDEX_KEY)))
>        {
>          return relationship;
>        }
>      }
>    }
>    return null;
>  }
>
> ...where getCommonRelationships returns an Iterable<Relationship> and
> simply loops through all the subject's relationships (of the specified
> relationship type and direction) until it finds an edge that points to the
> given object node.  The profiler says the 2/3 of the time is spent in
> org.neo4j.kernel.impl.core.IntArrayIterator.hasNext() and most of the rest
> is spent in org.neo4j.kernel.impl.core.RelationshipProxy.getOtherNode(Node).
>
> I am aware of the lab code that is supposed to support indexed edges and
> could see using that as a solution, but I was hoping for something native
> (and merged into the 1.1-SNAPSHOT branch).
>
> Are there any better approaches?
>
> Thanks,
> -Paul
> _______________________________________________
> Neo4j mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
>
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to