Criteria

Overview

The Criteria object is a commonly used model within the Clear API for defining complex filter rules. It is used when generating reports as well as searching across various resources.

A criteria is a recursively nested JSON object composed of branches of conditions, it takes the following base form:

{
    "COMPARATOR": [
        { FIELD },
        "VALUE"
    ]
}

The root key of a Criteria object is known as a Comparator, and the value will always be an Array of values to compare. This object is known as an Operation, and the power of the Criteria object comes in its ability to combine multiple operations together.

{
    and: [
        {
            "COMPARATOR": [
                { FIELD },
                "VALUE"
            ]
        },
        {
            "COMPARATOR": [
                { FIELD },
                "VALUE"
            ]
        }
    ]
}

At its most simplest, a criteria could simply be matching on a single field:

{
    "=": [
        { type: "attribute", key: "Country" },
        "Australia"
    ]
}

When used in Actor search, the above criteria will return all actors with a Country attribute matching Australia.

However, more advanced examples permit deep nesting to build infinitely complex filter rules:

{
    and: [
        { "=": [
            { type: "attribute", key: "Country" },
            "Australia"
        ] },
        { or: [
            { "=": [
                { type: "attribute", key: "Department" },
                "Marketing"
            ] },
            { "!=": [
                { type: "attribute", key: "Job Title" },
                "*Manager"
            ] }
        ] }
    ]
}

When used in Actor search, the above criteria will return all actors who meet the following conditions:

  • The actor must contain a Country attribute of Australia, AND;

  • The actor must match any of the following:

    • The actor must contain a Department attribute of Marketing, OR;

    • The actor must not contain a Job Title attribute ending in Manager

Reference

Comparators

Values

Last updated