Hi, I've just started looking at Neo4j and I'm quite intrigued.  However,
the cognitive dissonance that I've grown so used to in modeling storage is
proving to be a bit difficult to let go at this early stage :)

I was hoping that if someone could help me through an example I would be
able to grok how to properly structure my data and query it in Neo4j.

Nodes:
Message( text: String )
User( id: Long )

Relationships:
CREATED
FOLLOWS
IS_VISIBLE_BY

So I might have a graph with entries like so:

User(1) --> CREATED --> Message("i woke up late today")
User(2) --> CREATED --> Message("hello")
User(3) --> CREATED --> Message("ugh, i hate mondays")

User(1) --> FOLLOWS --> User(2)

Let's also say all messages are visible to User 1.

Message("i woke up late today") --> IS_VISIBLE_BY --> User(1)
Message("hello") --> IS_VISIBLE_BY --> User(1)
Message("ugh, i hate mondays") --> IS_VISIBLE_BY --> User(1)

So, I can do a simple traversal for visible:

val graphDb = new EmbeddedGraphDatabase( "path/to/neo4j-db" )
val index = new LuceneIndexService( graphDb )
val viewer = index.getSingleNode("id", 1)
val msgs = viewer.traverse( Order.BREADTH_FIRST, StopEvaluator.END_OF_GRAPH,
ReturnableEvaluator.ALL_BUT_START_NODE, Rels.IS_VISIBLE_BY,
Direction.INCOMING)
msgs.toList.map(_.toJson).mkString("{ msgs : [", ",", "] }")  // assuming i
have the relevant functions

But let's say that this is going to return too many messages.  Just because
all the messages are possibly visible to me, doesn't mean I want to see them
all.  So, I'd like to additionally filter by the FOLLOWS relationship.  I'd
like to express "get all messages that are visible and were created by a
user that I follow."  Can someone show me an example of how to do that?

I'm guessing that you need to implement a custom ReturnableEvaluator, but I
don't understand how you traverse multiple relationships at the same time.

Thanks,
Lincoln
_______________________________________________
Neo mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to