0

I am currently working on a query that pulls a list of viewed products for a user and then pulls a list of products purchased within orders. I would like to filter the list of viewed products against the list of products purchased with orders, with the result being a list of products viewed n times that were not purchased within an order.

Note my last clause - if I test with comma separate strings, it works.

g.V('84c0cb6c-6dd4-e2bd-a3f3-1a769637636e').store('User')
    .sideEffect(
        outE('TRIGGERS')
        .inV().as('UserSessions')
        .outE('VIEWS')
        .inV().as('UserWebpagesViewed')
        .outE('CONTAINS')
        .inV()
        .groupCount()
        .unfold()
        .where(
            select(values)
           .is(gte(2))
        )
        .select(keys)
        .store('UserMappedProducts')
    )
    .filter(inE('REFERS_TO').outV().inE('INSTANCE_OF').outV().outE('MAKES').inV())
    .sideEffect(
        inE('REFERS_TO')
        .outV()
        .inE('INSTANCE_OF')
        .outV()
        .outE('MAKES')
        .inV()
        .inE('PURCHASED_WITHIN')
        .outV()
        .id()
        .fold()
        .store('UserPurchasedProducts')
    )
    .select('UserMappedProducts')
    .unfold()
    .has(id, within(select('UserMappedProducts').unfold()))
  • I do not think I understand your query, but in general gremlin resolves stored sideeffect variables in the where() step, but not in the has() step. So, please try to end your query with .where(within('UserMappedProducts')) – HadoopMarc Jun 26 '22 at 18:13

1 Answers1

0

Adding to the comment above, as of today, Gremlin does not allow a traversal (such as select) inside a predicate like within. You can work around these types of limitations using the where....by forms of expression. Within the TinkerPop community we are interested in adding this capability to the Gremlin language.

There is a special case of where that treats the string inside a predicate and not a literal value if it is of the form where(somepredicate(somelabel))

In your specific case you would have to do something like:

.as('x').where(within('x')).by(id).by(select('UserMappedProducts'))
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38