Use wildcards in queries

When you use wildcard syntax with the Search API, Coveo expands keywords containing a wildcard character to the possible matching keywords to broaden the query. By default, wildcard characters are disabled when using the Search API.

Coveo supports the wildcard characters * and ?.

To enable them, set the wildcards query parameter to true. However, question mark characters (?) are disabled by default. To enable them, set the questionMark query parameter to true.

Note

With the Search API, developers can enable or disable wildcard match (wildcards) independently from the Coveo query syntax (enableQuerySyntax), which is set to true by default.

You can also leverage wildcard characters in advanced field queries. If you have querying issues, see Troubleshoot querying issues for troubleshooting guidelines.

Use the ? wildcard

You can use ? wildcard characters within a search term to allow some variability in your search. This can be useful when you’re unsure about the exact spelling for the name of a person, company, or product. See Using special characters in queries.

Examples
gr?y

Could return items containing either gray or grey.

te?t

Could return items containing either text or test, but could also return items containing te4t when this term exists in indexed items.

Use the * wildcard

You can use * wildcard characters when you want to match all variants of a pattern. You type the fixed part of the pattern and use a wildcard character to expand to the variants. In place of the wildcard, the variants can contain any number of any characters. See Using special characters in queries.

Examples
micro*

Could match Microsoft, microprocessor, microwave, micron, etc.

THI10*

Find all product names starting with THI10.

Use a wildcard in an exact phrase

You can use one or both wildcards in conjunction with quotation marks to find variants of a phrase (see Searching for a phrase).

Example
"fina* scandals 201?"

Returns items containing the following phrases :

  • financial scandals 2012

  • final scandals 2010

Use a wildcard with the NEAR operator

You can use wildcard characters with the NEAR operator.

Example
fina* NEAR:10 scandals

Returns items containing occurrences of words starting with fina that are within ten words from the word scandals, such as in the following phrases:

  • …​poor financial decisions led to these scandals…​

  • …​number of financial scandals…​

  • …​final decision. Due to the many scandals…​

Wildcard constraints

You can’t use wildcard characters in combination with an exact match prefix (see Searching for an exact term).

Moreover, wildcard queries can significantly expand a query and so consume more server resources than a typical query. To prevent this:

  • By default, at least two leading characters must precede the wildcard to restrict the number of wildcard terms candidates. Therefore, a query can’t begin with a wildcard.

  • The query expansion is limited by default to the first 32 wildcard terms found alphabetically. Increasing the maximum number of candidates can lead to performance issues, as more terms will have to be loaded for your wildcard expression.

  • A given wildcard expression may match a number of candidate items exceeding the maximum allowed by the index. In such a case, the Search API responds with a WildcardTooGeneral exception.

Tip

Wildcard queries on the entire content of an index always take longer to return results. For content where wildcards are appropriate, consider isolating the data in a field, and using the field for the wildcard search (see Advanced field queries). When searching in a field, the number of possibilities is smaller, so using the same wildcard expression may return more or even all possible results.