Thesaurus: Query pipeline feature
Thesaurus: Query pipeline feature
A query pipeline statement expressing the thesaurus
query pipeline feature defines how certain terms or phrases appearing in the basic part (q
) of the query expression should be expanded or replaced before executing the query against the index.
In general:
-
Expanding
A
toB
means: substituteA
with(A OR B)
. -
Expanding
A
toB
,C
means: substituteA
with(A OR B OR C)
. -
Replacing
A
withB
means: substituteA
withB
. -
Replacing
A
withB
,C
means: substituteA
with(B OR C)
.
The thesaurus
feature comprises four distinct sub-features:
-
alias
: expand each expression (keywords or phrases) in a list to all other expressions in that same list. -
expand
: expand each expression (keywords or phrases) in a list to all expressions in another list. -
replace
: replace each expression (keywords or phrases) in a list with all expressions in another list. -
quote
: replace each expression (keywords or phrases) in a list with its corresponding exact phrase match expression.
The following table summarizes how statements using each of the different thesaurus
sub-features would process the basic part (q
) of the combined query expression, assuming its current value is kitty cat
:
Statement definition | Processed q expression |
---|---|
|
|
|
|
|
|
|
|
|
|
Leading practice
Typically, a statement expressing the In general, you should ensure that this is the case by associating such a statement, and/or the query pipeline it’s defined in, to a global condition. |
Note
In the Coveo Administration Console, you can manage statements expressing the |
The following diagram shows the process of a query being sent to the Search API and the order of execution of query pipeline features.
Syntax
Use the following query pipeline language (QPL) syntax to define a statement expressing the thesaurus
feature:
alias <terms> | expand <terms> to <otherTerms> | replace <terms> to <otherTerms> | quote <terms> [to <otherTerms>]
<terms>
A comma-separated list of quoted strings and/or regular expressions, where each quoted string must contain one or more basic query terms (for example, "foo bar", "baz", /^meo+w$/
).
When using the |
<otherTerms>
A comma-separated list of quoted strings, where each quoted string must contain one or more basic query terms (for example, "hello world", "biz"
).
Note
If you define a named group in a regular expression in the For example, in an empty query pipeline named
The following table summarizes how the current
|
Using the alias
sub-feature
The alias
sub-feature lets you define statements that essentially make all expressions (keywords or phrases) in a set synonymous to one another.
This means that whenever any of these expressions appears in the basic part (q
) of the query expression, this expression expands to all other expressions in the alias
set.
alias
statements are evaluated in the order they’re defined.
This means that when a query is sent, the alias
sub-feature evaluates the terms defined in the statement in order until it finds a match with the queried keywords.
Therefore, when defining alias
statements that are meant to expand terms that share a single prefix, you should define more meaningful terms in the first position of the statement to avoid relevance issues.
In the Coveo Administration Console, alias
statements can be defined by using the Synonym thesaurus rule type.
When considering the following statement:
alias "vacation", "vacation leave", "vacation policy"
When a user queries vacation policy
, their query is parsed as follows:
(vacation OR (vacation leave) OR (vacation policy)) policy
However, when defining the same statement using vacation policy
in first position as follows:
alias "vacation policy", "vacation leave", "vacation"
The same vacation policy
query is parsed as follows:
(vacation policy) OR (vacation leave) OR vacation
An |
This sub-feature is an optimized use of the expand
sub-feature, as many statements would otherwise be required to define a set of bi-directional expansions (that is, synonyms).
-
The following statement:
alias "foo", "bar", "qux"
Is equivalent to:
expand "foo" to "bar", "qux" expand "bar" to "foo", "qux" expand "qux" to "foo", "bar"
-
In an empty query pipeline named
Testing Thesaurus Alias
, you create a statement expressing thethesaurus
feature with the following QPL definition:alias "car", /(dodge) \w+/, "automobile", "motor vehicle"
The following table summarizes how current
q
expression of different queries going through theTesting Thesaurus Alias
query pipeline is processed when this statement is applied:Current q
expressionProcessed q
expressioncar
car OR automobile OR (motor vehicle)
automobile
car OR automobile OR (motor vehicle)
motor vehicle
car OR automobile OR (motor vehicle)
dodge stratus
car OR (dodge stratus) OR automobile OR (motor vehicle)
dodge caravan car
(car OR (dodge caravan) OR automobile OR (motor vehicle)) (car OR automobile OR (motor vehicle))
Using the expand
sub-feature
The expand
sub-feature allows you to define statements that expand each expression (keyword or phrase) in an originating set to all expressions in a destination set.
Those expansions are uni-directional.
In the Coveo Administration Console, expand
statements can be defined by using the One-way synonym thesaurus rule type.
In an empty query pipeline named Testing Thesaurus Expand, you create a statement expressing the thesaurus
feature with the following QPL definition:
expand "car", /(dodge) \w+/ to "automobile", "motor vehicle"
The following table summarizes how the current q
expression of different queries going through the Testing Thesaurus Expand
query pipeline is processed when this statement is applied:
Current q expression |
Processed q expression |
---|---|
|
|
|
|
|
|
Using the replace
sub-feature
The replace
sub-feature allows you to define statements that replace each expression (keyword or phrase) in an originating set with all expressions in a destination set.
In the Coveo Administration Console, replace
statements can be defined by using the Replace thesaurus rule type.
In an empty query pipeline named Testing Thesaurus Replace
, you create a statement expressing the thesaurus
feature with the following QPL definition:
replace "car", /(dodge) \w+/ to "automobile", "motor vehicle"
The following table summarizes how the current q
expression of different queries going through the Testing Thesaurus Replace
query pipeline is processed when this statement is applied:
Current q expression |
Processed q expression |
---|---|
|
|
|
|
|
|
Note
You can use the
This can be useful when a product name has the same root as a frequently used keyword. |
Using the quote
sub-feature
The quote
sub-feature allows you to define statements that automatically turn all expressions (keywords or phrases) in an originating set into their corresponding exact phrase match expression, or into the corresponding exact phrase match expression of each expression in a destination set.
You could obtain the same results using the replace
sub-feature, but the required syntax would be heavier.
In the Coveo Administration Console, quote
statements can be defined by using the Match terms exactly thesaurus rule type.
-
The following statements:
quote "foo bar" quote /foo.*/
Are respectively equivalent to:
replace "foo bar" to "\"foo bar\"" replace /(?<fooGroup>foo.*)/ to "\"_fooGroup_\""
-
In an empty query pipeline named
Testing Thesaurus Quote
, you create two distinct statements, each expressing thethesaurus
feature, with the following QPL definitions:Statement 1
quote /(dodge) \w+/
Statement 2
quote "car", "automobile" to "motor vehicle"
The following table summarizes how the current
q
expression of different queries going through theTesting Thesaurus Quote
query pipeline is processed when these statements are applied:Current q
expressionProcessed q
expressiondodge stratus
"dodge stratus"
dodge stratus dodge caravan
"dodge stratus" "dodge caravan"
car
"motor vehicle"
automobile
"motor vehicle"
dodge stratus automobile
"dodge stratus" "motor vehicle"