apoc.path.expandConfig, node whitelisting

Hello

I want to use apoc.path.expandConfgi like below.

I have Nodes with these labels
1- PartRevision
2- Occurrence: some of Occurrence nodes have extra labels :Base/Deluxe. Occurrences nodes have both Base and Deluxe labels

I want to have a whitelistNode that are for PartREvision and only Occurrences that have 'Deluxe ' labels. I want Occurrences that have 'Base' label were blacklisted.

I am trying something like below. I am getting error on line 3 that variable t is not defined.

Is my Union correct for the purpose of generating whiltelistNodes? or there is a better to do whitelist nodes ? I prefer to have blacklisted implemented that I can add more nodes that have other labels. How can I blacklist nodes that have ONLY Occurrence/Base and don't have Deluxe ?
( reminder that soem occurences have both Base/Deluxe)

also how can i pass t to apoc.path.config ?

match ( t:PartRevision) where t.name = 'CROSSKART_DC' 
match ( o:Deluxe ) return o union match (p:PartRevision) return p as X 
WITH t , collect ( X) as AllowedOccurences
CALL apoc.path.expandConfig(
    t,
    {
        relationshipFilter:"HAS_PARENT|`Latest Working`",
        uniqueness: "NODE_GLOBAL",
        whitelistNodes : AllowedOccurences
    }) YIELD path
RETURN path

Try this:

match (t:PartRevision) 
where t.name = 'CROSSKART_DC'
call {
    match (x:Deluxe) 
    return x
    union 
    match (x:PartRevision) 
    return x
}
WITH t, collect (x) as AllowedOccurences
CALL apoc.path.expandConfig(
t,
{
    relationshipFilter:"HAS_PARENT|Latest Working",
    uniqueness: "NODE_GLOBAL",
    whitelistNodes : AllowedOccurences
}) YIELD path
RETURN path

If you are using version 5, the following should work the same:

match (t:PartRevision) 
where t.name = 'CROSSKART_DC'
match (x:Deluxe|PartRevision) 
WITH t, collect (x) as AllowedOccurences
CALL apoc.path.expandConfig(
t,
{
    relationshipFilter:"HAS_PARENT|Latest Working",
    uniqueness: "NODE_GLOBAL",
    whitelistNodes : AllowedOccurences
}) YIELD path
RETURN path

With version 4, the following should work too:

match (t:PartRevision) 
where t.name = 'CROSSKART_DC'
match (x) where x:Deluxe or x:PartRevision
WITH t, collect (x) as AllowedOccurences
CALL apoc.path.expandConfig(
t,
{
    relationshipFilter:"HAS_PARENT|Latest Working",
    uniqueness: "NODE_GLOBAL",
    whitelistNodes : AllowedOccurences
}) YIELD path
RETURN path
1 Like

Thank you Gary

what is difference between using labelFilter in below and your suggestions with having explicit matches ?

or better question what will be dfference for using WhiteListNodes compared to labelFilter?

match ( t:PartRevision) where t.name = 'CROSSKART_DC'
WITH t
CALL apoc.path.expandConfig(
t,
{
labelFilter:"PartRevision, Deluxe",
relationshipFilter:"HAS_PARENT<, +Latest Working> | -Engineering Released>",
uniqueness: "NODE_GLOBAL",
minLevel : 1,
maxLevel : 3,
bfs : false
}) YIELD path
RETURN path , length(path ) as hops
order by hops

I was just following your initial query to make the syntax work. I think in your case, both implementation will provide the same results, as the the white node list is comprised of all nodes with the same two labels as you have in your "allow" node labels. In terms of performance, I would think your implementation with labels will be more efficient, as it eliminates the need to query to get the specific nodes and to compare each path node to the nodes in the allow list. The label filtering will be incorporated as part of the transversal operation, so it should not add much overhead.

Hi @shsamardar,

Keep into consideration that querying nodes first in order to use them as a list will include a memory overhead due to the need of an explicit eager collection. Using label filters, conditions will be evaluated runtime.

1 Like

Hi @shsamardar ,

Are the has parent and latest working releationships only connecting PartRevision and Occurrences? if is that the case, this should work. If not, hopefully ill give you an idea of the nodeFilter usage.

MATCH( t:PartRevision) where t.name = 'CROSSKART_DC' 
CALL apoc.path.expandConfig(
    t,
    {
        relationshipFilter:"HAS_PARENT|`Latest Working`", //You may like to add directions
        labelFilter : "+Deluxe|+PartRevision"
        uniqueness: "NODE_GLOBAL"
    }) YIELD path
RETURN path