Advanced Field Queries

The Coveo query syntax includes special field operators to perform advanced matches. These advanced field queries perform the match directly on field values rather than through the index, as is the case for regular field queries.

The benefit of advanced field queries is that you can search field values for occurrences of special characters which are typically not searchable because they’re not indexed (e.g., dots, dashes, parentheses, etc.), and which can act as search prefixes or operators.

You can only use an advanced field query if the queried field is a facet field.

Advanced field query search results will return within 1 second. However, when the number of items, possible field values, or complexity of the matching expression (for regular expressions) increases, or when field values aren’t loaded in cache memory, this will take more time.

Advanced Field Query Syntax

The advanced field query syntax is:

@<FIELD_NAME> <ADVANCED_FIELD_OPERATOR> "<VALUE>"1

Advanced field operator Description
*= Wildcard Match
~= Fuzzy Match
%= Phonetic Match
/= Regular Expression Match
  • The wildcard, fuzzy, phonetic, and regular expression advanced field queries are case-insensitive and aren’t subject to stemming.

1: Space characters on either side of the operator are optional.

Wildcard Match

Wildcard matches broaden the search results by introducing some variability into the query string. The wildcard match operator (*=) interprets any wildcard characters (?, *) which are present in the field value (“<VALUE>”) without the restrictions that usually apply when you use wildcard characters in an index query.

You can use one or more wildcard characters anywhere in the field value, and all possible combinations will be matched.

  • @author *= "*son"

    Matches would include: E. Johnson, ejohnson, catherine_manson, etc.

  • @filename *= "*.mp?"

    Matches any MP3 or MP4 file name.

  • @title *= "colo*r"

    Matches titles that contain either the color or the colour spelling.

Fuzzy Match

Fuzzy matches broaden the search results by allowing for some variance between the query string and the matched results. The fuzzy match operator (~=) searches for matches that vary by up to 20% from the queried value (i.e., the matches can be up to 20% longer or shorter, can contain up to 20% different characters, or any combination thereof).

  • @syslanguage ~= "lituanian"

    The correct spelling of the lithuanian language is one character longer than the queried value. The correctly spelled language will be returned as a match because it only varies from the query string by 11% (i.e., it’s 1 character longer than the 9 characters in the query).

  • @syslanguage ~= "lituanien"

    The correct spelling of the lithuanian language is one character longer than and differs by one character from the queried value. The correctly spelled language will not be returned as a match because it varies from the query string by 22%.

Using a Wildcard in a Fuzzy Match

You can only add a wildcard (*) to the end of a fuzzy query. If the * character appears anywhere else, it isn’t interpreted as a wildcard.

  • @sysauthor ~= "Dipartiment*"

    The queried value (not including the wildcard character) is 11 characters long, so matches can vary by up to 2 characters. As with any other wildcard match, all possible combinations that match the wildcard will be returned, regardless of length. In this case, for example, Department, Department of Justice, and Department of Defense would all be matching values.

Phonetic Match

The phonetic match operator (%=) converts the queried value to phonetic codes, compares these codes to the phonetic codes of all possible field values, and returns those that share some of the same phonetic codes.

Phonetic match can be used to find variants of people’s names.

@sysauthor %= "Georg"

Value Phonetic codes Matches
Georg JRK and KRK George and Jörg
George JRJ and KRK Georg
Jörg JRK and ARK Georg

Phonetic match looks for the phonetic codes for several languages with a limited phonetic code complexity. Consequently, the matching results may appear incomplete, particularly for long queried values.

Regular Expression Match

The regular expression (regex) operator (/=) applies the regular expression entered as the field value to match precise content. The regex uses a match operation to match the entire content of the field.

Use the ECMAScript regular expression syntax implemented by JavaScript.

Matches user names that are in email form.:

@username /= "[\w\.%\+]+@[a-zA-Z0-9\.\-]+\.[A-Za-z]{2,4}"

Recommended Articles