Skip to content

Operators

MQL syntax supports various operators that you can use to build more complex queries.

The following table briefly describes the MQL operators.

Operator Use Example
AND The result of expression x AND y is TRUE when both x and y evaluate to TRUE. website AND problem
OR The result of expression x OR y is TRUE when either x or y evaluate to TRUE purchase OR buy
& A synonym of operator AND website & problem
| A synonym of operator OR purchase | buy
NOT The result of expression NOT z is TRUE when z evaluates to FALSE NOT "replacement order"
NOTIN The result of expression x NOT y is TRUE when x evaluates to TRUE, but x doesn't overlap with y problem NOTIN "not a problem
NEAR The result of expression x NEAR:5 y is TRUE when both x and y evaluate to TRUE and a distance between them is no more than 5 cancel NEAR:3 order
NOTNEAR The result of expression x NOTNEAR:5 y is TRUE when x evaluates to TRUE and y either evaluates to FALSE or is found in a transcript at a distance of more than 5 number NOTNEAR:3 phone
ONEAR The result of expression x ONEAR:5 y is TRUE when both x and y evaluate to TRUE and a distance between them is no more than 5, and x appears in a transcript before y cancel ONEAR:3 order
AFTER The result of expression x AFTER:5 y is TRUE when both x and y evaluate to TRUE and x appears in a transcript before the y at a distance no more than 5 R"[0-9]+" AFTER:20 "credit card"
POSBEFORE The result of expression POSBEFORE:50 x is TRUE when x evaluates to TRUE and x appears in a transcript in the first 50 words `POSBEFORE:50 "my name is"
POSAFTER The result of expression POSAFTER:50 x is TRUE when x evaluates to TRUE and x appears in a transcript after the 50th word. A position can be negative, where POSAFTER:-50 means the last 50 words of a transcript `POSAFTER:-50 "Have a great day"
AGENT The result of expression AGENT: x is TRUE when x evaluates to TRUE and the matched phrase was spoken by agent AGENT: "my name is"
A A synonym to AGENT A: "my name is"
CUSTOMER The result of expression CUSTOMER: x is TRUE when x evaluates to TRUE and the matched phrase was spoken by customer CUSTOMER: "my name is"
C A synonym to CUSTOMER C: "my name is"
REPEATS The result of expression REPEATS:5-10 x is TRUE when x evaluates to TRUE and appears in a transcript between 5 to 10 times REPEATS:5-10 "great"

Grouping

Multiple expressions can be grouped with parentheses to form a more complex expression.

Examples:

Expression Description
(quick OR brown) AND fox matches "quick fox", "brown fox", but not "grey fox"
cancel* NEAR (order|account) matches "cancel order", "order is cancelled", "I am cancelling my account", "I want to cancel this order"
problem NOTIN ("no problem" OR "not a problem") matches "This is a problem", but ignores "no problem at all", and "not a problem"

Precedence rules

When no parentheses are present, then the operators are evaluated in the following order:

  • NOTNEAR
  • ONEAR
  • NEAR
  • NOTIN
  • REPEATS
  • AGENT, A, CUSTOMER, C
  • POSAFTER
  • POSBEFORE
  • Metadata comparison characters, like $sentiment < -10
  • NOT
  • AND
  • OR
Expression Equivalent form
quick OR brown AND fox quick OR (brown AND fox)
quick NEAR brown AND fox (quick NEAR brown) AND fox

Default operator

If no operator is included between terms, then a default ONEAR:5 operator is used:

Expression Equivalent form
brown fox brown ONEAR:5 fox
(quick OR brown) fox (quick OR brown) ONEAR:5 fox
quick OR brown fox quick OR (brown ONEAR:5 fox)

Note

The ONEAR operator has a higher priority than OR and AND (see the Precedence rules section).

For example, the expression quick AND brown fox is interpreted by the search engine as quick AND (brown ONEAR:5 fox)

Boolean operators (AND, OR, NOT, & and |)

Expression Description
quick OR brown matches "quick fox" and "brown fox"
quick AND fox matches "quick fox"
NOT brown AND fox matches "quick fox" but not "brown fox"

Synonyms & and I

Symbols & and | are synonyms for AND and OR respectively.

Expression Equivalent form
quick | brown quick OR brown
quick & fox quick AND fox
(quick | brown | grey ) & fox (quick OR brown OR grey) AND fox

When using | and & symbols, a space charter between words is optional. The following are valid expressions:

  • (quick | brown | grey ) & fox
  • (quick|brown|grey)&fox

Case in operator names

A case in the operator's name is important. AND is treated as an operator, while and is treated literally as a word "and" in the text "what a beautiful and amazing day".

Order of the matched terms

For boolean operators, and order of the matched words is not taken into account. If an order is important, then use the ONEAR operator.

Expression Description
quick AND fox matches both "quick fox" and "fox quick"

Distance between the matched terms

For boolean operators, a distance between words is not taken into account, i.e. the expression x AND y will evaluate to TRUE when terms x and y are found anywhere in a transcript. Use Quoted Term or operators NEAR, ONEAR and NOTNEAR if a distance is important.

Expression Description
quick AND fox matches both "quick fox" and "quick dog was chasing a fox"
"quick fox" matches "dog was chasing a quick fox" bot not "quick dog was chasing a fox"
quick NEAR:3 fox matches "quick fox" and "quick and cute fox" but not "quick dog was chasing a fox", because of a distance between quick and fox words is more than 3 words.

Proximity operators (NEAR, ONEAR, NOTNEAR, NOTIN, AFTER)

Proximity operators allow you to locate one searched term within a certain distance of another.

NEAR[:x]

Finds the phrase where the terms joined by the operator are within the specified number of words of each other. Where x is the maximum distance between the searched terms.

Key features:

  • A distance parameter is optional. If omitted, a default distance of 5 is used, i.e. NEAR is equivalent to NEAR:5

  • An order of the found terms is not taken into account, i.e. brown NEAR fox will match both "dog is chasing brown fox" and "fox is chasing brown dog".

  • When chaining multiple operators, then parentheses must be used if the distance is not the same.

    For example, expressions brown NEAR quick NEAR fox and brown NEAR:2 quick NEAR:2 fox are both valid, but brown NEAR:2 quick NEAR:5 fox is not a valid expression because a distance is 2 in one case and 5 in another. Parentheses must be added to make such expression valid: (brown NEAR:2 quick) NEAR:5 fox

Expression Description
cancel* NEAR order Matches "cancel my order", "order is cancelled", but not "cancel my account and then place an order", because of a distance between cancel and order in the last example is more than default 5 words.
cancel* NEAR:1 order Matches "cancel order", but not "cancel my order" because of distance between words is more than requested (1).
brown NEAR quick NEAR fox Matches "brown and quick fox", but not "brown fox"

ONEAR[:x]

Similar to the NEAR operator, but an order of the matched terms is taken into account. For example, brown NEAR fox will match "brown fox" but not "fox brown".

Expression Description
cancel* ONEAR order Matches "cancel my order" but not "order is cancelled", because of the order of terms is important.

Key features:

  • A distance parameter is optional. If omitted, a default distance of 5 is used, i.e. ONEAR is equivalent to ONEAR:5

  • When chaining multiple operators, then parentheses must be used when the distance is not the same.

    For example, expressions brown ONEAR quick ONEAR fox and brown ONEAR:2 quick ONEAR:2 fox are both valid, but brown ONEAR:2 quick ONEAR:5 fox is not a valid expression because a distance is 2 in one case and 5 in another.

    Parentheses must be added to make such expression valid: (brown ONEAR:2 quick) ONEAR:5 fox

NOTNEAR[:x]

Syntax:

<term-1> NOTNEAR[:x] <term-2>

Operator NOTNEAR finds the term on the left side of the operator (<term-1>) that is not near the term on the right side of the operator (<term-2>).

Expression Description
cancel* NOTNEAR account Matches "cancel order", "order is cancelled", but neither "cancel my account" not "this account is cancelled".
cancel* NOTNEAR:1 account Matches "cancel my bank account" but not "cancel account", because of a required distance between terms is maximum 1.

Key features:

  • A distance parameter is optional. If omitted, a default distance of 5 is used, i.e. NOTNEAR is equivalent to NOTNEAR:5

  • An order of the found terms is not taken into account, i.e. cancel* NOTNEAR account will exclude both "cancel account" and "account canceled"

  • Chaining of operator NOTNEAR is not supported.

    Use parentheses to specifically group multiple expressions.

    For example, cancel* NOTNEAR bank* NOTNEAR account must be rewritten as cancel* NOTNEAR (bank* NOTNEAR account)

NOTIN

Operator NOTIN allows matching terms that are not part of a longer term. For example, you would like to find the word "problem", but not when it is part of the phrase "not a problem".

Examples:

  • problem NOTIN "not a problem"
  • problem NOTIN "no problem"
  • problem NOTIN ((no|not) ONEAR problem)
  • problem NOTIN no* ONEAR:2 problem

AFTER[:x]

Finds the phrase that appears in a transcript after another phrase.

An optional argument after the colon symbol (x) is the maximum distance between the searched terms.

Key features:

  • A distance parameter is optional. If omitted, a default distance of 5 is used, i.e. AFTER is equivalent to AFTER:5

  • The operator AFTER is partially equivalent to the ONEAR operator, i.e. the search expression you AFTER thank can be replaced with thank ONEAR you.

    But there is one key difference between the AFTER and ONEAR operators: the result of the ONEAR expression is a whole matched text as a match ("thank you" in our example), while the result of the AFTER expression is the left term only ("you" in our example).

    This becomes very handy when using data redaction functionality with search expressions like R"[0-9]+" AFTER "credit card", which has a purpose of redacting digits from audio recording and transcript while keeping the text "credit card" intact.

    The equivalent expression "credit card" ONEAR R"[0-9]+" would redact both the phrase `"credit card", digits and any other text in between these two found terms.

Expression Description
R"[0-9]+" AFTER "credit card" Matches "123456" in phrase "my credit card number is 123456" but not in "my phone number is 123456"

Count occurrences (REPEATS)

Operator REPEATS finds the term, that occurs the requested number of times in a text. For example, it can be used to find the phrase where at least 8 digits are spoken.

Syntax:

REPEATS:N[-M] <term>

Where:

  • <term> is a search expression, which can be a word, phrase or a complex expression like (brown | quick)
  • N is the minimum number of occurrences of the term in the text
  • M is the maximum number of occurrences of the term in the text. If omitted, then maximum M is equal to N, i.e brown MATCHES: 2 is the same as brown MATCHES: 2-2

Examples:

  • REPEATS:5-10 (great|appreciate)

In some cases, a Regex pattern matching can be used as an alternative to REPEATS operators.

For example, to find consecutive digits in a text, use the expression like:

R"([0-9][ ]*){3,10}"

Such an expression will match digits 0 to 9 in a text, optionally, separated with a space character, and requires a minimum 3, maximum 10 digits.

It is partially equivalent to the following REPEAT query:

REPEATS:3-10 (0|1|2|3|4|5|6|7|8|9)

We say partially because the REPEATS operator matches whole words, while REGEX operator can match part within the words.

For instance, both expression will successfully match the digits in the text "credit card number is 1 2 3 4 5 6 7 8".

But, if the digits appear in a text as a single word, like in "credit card number is 12345678", then the REPEATS operator would not match this text, while REGEX operator successfully matches it.