Indexing Pipeline Extension Condition Syntax Reference

You can optionally add conditions on your extensions to control on which items they must be executed. The condition is part of the extension configuration when you apply the extension to a source, not in the extension Python script itself. This way, the Coveo indexing pipeline loads and executes the extension only for items for which the condition evaluates to True, allowing to optimize crawling performances.

You can apply an extension to a given source and specify a condition from the Coveo Administration Console (see Apply an Extension to a Source). Alternatively, you can also apply an extension to a given source and specify a condition using the Coveo API (see Apply an Extension to a Source).

See the information below for extension condition syntax and examples.

Syntax

Indexing pipeline extension conditions are essentially built with metadata, metadata values, and operators.

  • Metadata syntax: %[metadataName]

  • Supported operators: ==, NOT, AND, OR, ()

Notes
  • Operators are case insensitive.

  • Values can be delimited in single or double quotes ("value" and 'value' are equivalent and can be mixed in the same condition).

  • Metadata name can contain special characters (such as %, ], [, " etc), but they must be escaped (for example, %[meta1\[test\]] is valid, %[meta1[test]] is not).

  • Extensions without conditions are executed for all items.

Condition Syntax Examples

The following table presents examples of the different condition syntax features that can help you apply useful indexing pipeline extensions to sources (see Apply an Extension to a Source).

Condition syntax example Evaluate to true if

%[meta1]

The metadata meta1 exists on the item.

NOT %[meta1]

The metadata meta1 doesn’t exist on the item.

%[meta1] == "value"

The value of meta1 equals value.

NOT %[meta1] == "value"

The metadata meta1 doesn’t exist, or it exists but its value isn’t equal to value.

%[meta1] AND NOT %[meta1] == "value"

The metadata meta1 exists, and its value isn’t equal to value.

%[meta1] AND %[meta2]

Both metadata exist on the item.

%[meta1] == "value" AND %[meta2] == "value"

Both metadata values equal value.

%[meta1] OR %[meta2]

At least one of the metadata exists on the item.

%[meta1] == "value" OR %[meta2] == "value"

At least one of the metadata value equals value.

(%[meta1] OR %[meta2]) AND %[meta3]

At least one of the metadata joined by OR exists on the item.

The metadata meta3 exists on the item.

Note

When using more than one operator in a condition without parenthesis, the condition is evaluated with the following operator priority: NOT > AND > OR.

%[meta1] == ["value1", "value2"]

The metadata meta1 equals either ["value1", "value2"] or ["value2", "value1"].

Pitfalls to Avoid

  • You can’t directly compare one metadata to another (for example, %[meta1] == %[meta2]).

    Rather use: %[meta1] == 'value' AND %[meta2] == 'value'

  • You can’t use operators between values (for example, %[fruit] == 'apple' OR 'orange' isn’t valid).

    Rather use: %[fruit] == 'apple' OR %[fruit] == 'orange'

  • You can’t use the inequality operator !=.

    Rather use NOT %[meta1] == 'value'.

  • Conditions don’t support specifying an origin (crawler, converter, mapping). The comparisons are always done using the latest value for the metadata so you must be aware of the indexing pipeline stage at which your extension is executed.