Question

I have a linked list of activities for a user, like this :

(user)-ACTIVITIES->(activity)-NEXT*->(activity)->...

Each activity node is related to a source node and a target node

(theSource)<-SOURCE-(activity)-TARGET->(theTarget)

I want to retrieve all activities, with a filter on the source. How can I filter with a source node ? I Want to filter activities, where source.email = 'someone@email.com'. This code does not work :/

g.v(1).out('ACTIVITIES')
.as('x')
.out('NEXT')
.loop('x'){it.loops <= 10}{true}
.filter{
    it.out('SOURCE').email == 'someone@email.com'
}

How can I filter with a linked node in the filter closure ? Is this a good way to do that ?

Regards

Was it helpful?

Solution

You need to next() your pipeline in the filter. It should be:

.filter{
    it.out('SOURCE').email.next() == 'someone@email.com'
}

Without the next you are doing an equality on a Pipeline which will never return true.

As an added suggestion I would recommend you change your emit closure (the second one) on the loop. The emit closure controls the items that escape the pipe. By setting to true as you have it now it is emitting everything and then you are applying the filter. A bit more compact way to do it would be to make your traversal look like this:

g.v(1).out('ACTIVITIES')
.as('x')
.out('NEXT')
.loop('x'){it.loops <= 10}{it.out('SOURCE').email.next() == 'someone@email.com'}

In this way you handle the filtering in the emit closure as opposed to a separate step of the pipeline.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top