Querying deep inside a graph, doubts about how to do it...

14 views
Skip to first unread message

Tiago Scolari

unread,
Mar 5, 2012, 3:08:58 PM3/5/12
to Neo4j
Hello, I started using Neo4j few days ago, I read all the
documentation but I still have few doubts.
I belive that what I'm trying to do is simple, but I'm having a hard
time figuring out how to do it.

I have nodes that represent articles and nodes that represent tags.
And I've 2 types of relations [article ---has_tags--> tag] and [tag --
has_article--> article].

What I want is, given a tag node, find all related tags, that are
those that share an article at first level (I did) or that has one or
more articles connecting them indirectly

tag ----> article ----> tag (first level) ----> article ---> tag ---
> ...

Finding the first tags was easy:

START tags=node(6)
MATCH tags-[:has_article]->article-[:has_tags]->related_tag
WHERE tags.name != related_tag.name
RETURN related_tag.name, COUNT(related_tag.name)

I dont know how to travel deeper in the graph. I would like to some
how give more relevance to tags closer, but I could not even list tags
that are not direct linked by an article.
I tryed this (based on an example):

START tags=node(6)
MATCH tags-[:has_article*0..]->article-[:has_tags*0..]->related_tag
WHERE tags.name != related_tag.name
RETURN related_tag.name, COUNT(related_tag.name)

but it was not what I expected...
Any help? please? =p

Peter Neubauer

unread,
Mar 8, 2012, 7:11:07 AM3/8/12
to ne...@googlegroups.com
Tiago,
do you have a sample graph or DB you could share? What result are you expecting?

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

Reply all
Reply to author
Forward
0 new messages