Skip to main content

Filtering

If you want to filter the nodes according to some condition or a specific property value, the filter() expression returns all nodes for which the condition is true

It takes the generic form of:

nodes().filter([condition])

The most efficient way to filter nodes based on properties is to use filter() in combination with the is. predicate library

Some examples using the is predicate library in filters() would be

Filter on the value of a propertyโ€‹

In its simplest form nodes may be filtered based on the one property containing a single value

To list all the women in the organization:

nodes().filter(is.prop("gender", "Female"))

image

This can be extended further to filter for multiple values in a property using the .in function

nodes().filter
(is.prop("Absence Detail",is.in("Stress", "Other")))

In this example the expression has returned a collection of nodes who have the "Absence Detail" reason of either "Stress" OR " Other" using the .in function

image

Filter on a node functionโ€‹

This method allows filtering based on a generated property using Is Node Functions. See also Generated Properties for further details of generated properties

To list anyone without a manager or reports

nodes().filter(is.orphan)

image

To list all managers

nodes().filter(is.parent)

image

Filter children of a node using a propertyโ€‹

List all of someoneโ€™s direct reports with an Performance Ranking score greater than or equal 6

node.c.filter(is.prop("performanceRanking", is.gtEq(6)))

image

Filter using a lambdaโ€‹

Lambda expressions n => n allow you to take a set of collections and apply a method to every member of the collection see Lambda Expression for more details

List the employees whose grade is the same as their parent's grade

nodes().filter(n => n.grade.isEq(n.p.grade))

image