Thesaurus rule syntax with numeric and Boolean parameters

In this article

Thesaurus rules could break some query extensions in specific scenarios.

When a thesaurus rule applies to a number or a Boolean and these values aren’t between single quotes in the query extension, the values are expanded and cause an error.

Thesaurus rule: expand 300, 30

Query extension: $qre(expression: foo bar, modifier: 300)

Result: $qre(expression: foo bar, modifier: 300 OR 30) -> Query error

Always surround numeric/Boolean parameters with single quotes.

Thesaurus rule: expand 300, 30

Query extension: $qre(expression: foo bar, modifier: ‘300’)

Result: $qre(expression: foo bar, modifier: ‘300’) -> Works

This happens because the Coveo Search API parses the different query arguments of an extension and manages the parameters differently depending on the type.

If the parameter isn’t surrounded by single quotes, it will be considered as an expression that needs to be expanded. If the parameter is surrounded by single quotes, it will be considered as a literal and won’t be expanded. The same principle applies to parameters that contain expressions.

If you want an expression to be expanded, which is typically the case, don’t surround it with single quotes.