cancel
Showing results forΒ
Did you mean:Β

## Is there a way to implement a function that filters for a variable number of predefined attributes with a respective minimum and maximum value?

Node

Is there a way to implement a function that filters for a variable number of predefined attributes with a respective minimum and maximum value?

I can manage for a fixed number of attributes, but I want to keep the number variable. Something like:
information in a list :
dictionary1: attribute_name1 - min1 - max1
dictionary2: attribute_name 2 - min2 - max2
dictionary3: attribute3 - min3 - max3
-> filter for all elements where the attributes are in the given range
MATCH(a:node_label)
WHERE a.attribute1>min1 AND a.attribute1min2 AND a.attribute2min3 AND a.attribute3<max3
return a

it should also work if I only have these attributes in the list:
dictionary1: attribute1 - min1 - max1
dictionary2: attribute2 - min2 - max2
-> filter for all elements where the attributes are in the given range
MATCH(a:node_label)
WHERE a.attribute1>min1 AND a.attribute1min2 AND a.attribute2<max2
return a

or if there is a random number of dictionaries in the list

I tried it with unwind, but then I have only the attributes for one dictionary available at the same time to use it in WHERE. The problem is I need to connect the WHERE statement of all dictionary together...
Anyone an idea?

1 ACCEPTED SOLUTION
Ninja

You can try the following if you want pure cypher. Define your list of constraints in the with clause.

``````with [{prop: 'x', min: 1, max: 3}, {prop: 'y', min: 10, max: 15}] as constraints
match(n:node_label)
where all(i in constraints where i.min <= n[i.prop] <= i.max)
return n
``````
2 REPLIES 2
Ninja

You can try the following if you want pure cypher. Define your list of constraints in the with clause.

``````with [{prop: 'x', min: 1, max: 3}, {prop: 'y', min: 10, max: 15}] as constraints
match(n:node_label)
where all(i in constraints where i.min <= n[i.prop] <= i.max)
return n
``````
Node

Thank you, this works beautifully

Nodes 2022

NODES 2022, Neo4j Online Education Summit

OnΒ November 16 and 17 for 24 hours across all timezones, youβll learn about best practices for beginners and experts alike.

Neo4j Resources