Advanced Field Queries

The Coveo query syntax includes special field operators that perform advanced types of matches.

The advanced field query syntax is:

@fieldname [Advanced_field_operator] "value"

where space characters on either side of the operator are optional.

Advanced field operator Description
*= Wildcard Match
~= Fuzzy Match
%= Phonetic Match
/= Regular Expression Match

The advanced field queries perform the match directly on the field values, not through the index like it is the case for regular field queries (see Field Queries). Consequently, an advantage of advanced field queries is that you can search in field values for occurrences of special characters that are normally not searchable because they are not indexed and can act as search prefix or operators (see Search Prefixes and Operators).

With advanced field queries, you can search in field values for strings that include dots, dashes, slashes, parentheses, brackets, currency symbols, etc.

Requirements

  • Search results for advanced field queries will typically be returned well within 1 second, like normal queries. They can however take more time when the number of items, the number of possible field values, and the complexity of the matching expression (particularly for regular expressions) increase, or when field values are not loaded in cache memory.

  • The wildcard, fuzzy, phonetic, and regular expression advanced field queries are case-insensitive and not subject to stemming.

Wildcard Match

The wildcard advanced field operator (*=) interprets wildcard characters (?, *) present in the field value without the restrictions that usually apply when you use wildcard characters in a index query (see Using Wildcards in Queries). You can therefore use one or more occurrences of wildcard characters anywhere in the value, and all possible combinations will be matched.

Wildcard matches are useful to broaden search results with variability in specific query string locations.

  • @author *= "*smith"

    You can put a wildcard character at the beginning of the field value to match any first name or first name abbreviation. Possibles matches would be: J. Smith, jsmith, John Smith, John Edward Smith, John Sexsmith, 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

The fuzzy match advanced field operator (~=) looks for values that are approximately the same as the queried value by allowing a reasonable sample (approximately 20%) of the queried characters to be different, missing, or added.

  • @syslanguage ~= "lituanian"

    The queried value contains 9 characters, so only 1 character can be different, missing, or added in matching values. This matches the correct language name spelling lithuanian that contains one more character.

  • @syslanguage ~= "lituanien"

    This queried value still contains 9 characters, but 2 errors relative to the correctly spelled language name, so lithuanian is not matched.

You can also add wildcard * at the end of the queried value to apply the fuzzy match only to the start of the possible values, allowing any combination after. However, the * character appearing anywhere else is not interpreted as a wildcard.

  • @sysauthor ~= "Dipartiment*"

    The queried value has 11 characters, so up to 2 characters can be different, missing, or added in the first 11 characters of matching values, so Department of Justice or Department of Defense are matching values.

Phonetic Match

The phonetic match advanced field operator (%=) looks for values that sound similar to the queried values. Technically, a phonetic match query converts the queried value to phonetic codes, compares them with the phonetic codes of all possible field values, and returns those that share some phonetic codes.

The phonetic match can be useful to find people name variants.

@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

The phonetic match tries to obtain the phonetic codes for several languages with a limited phonetic code complexity. Consequently, the matching results may sometimes appear incomplete, particularly for long queried values.

Regular Expression Match

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

You can use the regular expression advanced field operator to:

  • Match username field values that are in an email form:

    @username /= "[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}"

  • Match item title field values that contain a specific string such as create:

    @systitle /= ".*create.*"

Use the ECMAScript regular expression syntax implemented for example by JavaScript (see Using Regular Expressions with JavaScript).