1
votes

I'm learning to use Gremlin in Neo4j.

I have the following structure of tags: Sport - > (related) -> Football - > (related) -> Belgium.

At each Tag I have Feeds associated. At each Feed, I have several items feed (news) .

When I search the feeds of Sport, also want to pull all related to Football and Belgium (his related Tags).

With Cypher I get result with this query:

START tag=node(106949) MATCH tag-[:FILHA*1..10]->fof WITH fof MATCH fof-[:USA]->feeds RETURN feeds LIMIT 10;

With Gremlin I get all the tags related to the Sport tag with this:

x=[];g.v(106949).as("tagsFilha").out("FILHA").aggregate(x).loop("tagsFilha"){it.loops < 10}.iterate();x

With Gremlin could catch the news feeds of a tag ( Sport ) as follows:

g.v(startNode).out("USA").out("CONTEM").sort{it.qtde_visualizacoes}._()[0..10]

But above query didn't return news associated to related Tag. ex : Searching for Sport also get the news of Tag Belgium too (his related Tag).

Can anyone point me an reference?

thanks!

1

1 Answers

0
votes

I'm not sure I completely follow your schema, but if you've already have all the Sport tags in x with this:

x=[];g.v(106949).as("tagsFilha").out("FILHA").aggregate(x).loop("tagsFilha"){it.loops < 10}.iterate();x

and you know that this gets you your feeds:

g.v(startNode).out("USA").out("CONTEM").sort{it.qtde_visualizacoes}._()[0..10]

then why not just start a pipeline from x to get the feeds in the same way:

x._().out("CONTEM").sort{it.qtde_visualizacoes}._()[0..10]

So, in other words, for all the tags that are in the hierarchy, just traverse to the feeds.