Support Menu

Class QueryBuilder

Class QueryBuilder

The QueryBuilder is used to build a IQuery that will be able to be executed using the Search API.
The class exposes several members and methods that help components and external code to build up the final query that is sent to the Search API.

Index

Methods

addContext

  • addContext(values: object): void
  • Add a context object to the query.
    This can contain multiple key->value.
    This is used by the Query pipeline in the Coveo platform.

    Parameters

    • values: object
      • [key: string]: any

    Returns void

addContextValue

  • addContextValue(key: string, value: any): void
  • Add a single context key->value pair to the query.
    This is used by the Query pipeline in the Coveo platform.

    Parameters

    • key: string
    • value: any

    Returns void

addFieldsToExclude

  • addFieldsToExclude(fields: string[]): void
  • Add fields to specifically exclude when the results return.
    This can be used to accelerate the execution time of every query, as there is much less data to process if you blacklist specific fields.

    Parameters

    • fields: string[]

    Returns void

addFieldsToInclude

  • addFieldsToInclude(fields: string[]): void
  • Add fields to specifically include when the results return.
    This can be used to accelerate the execution time of every query, as there is much less data to process if you whitelist specific fields.

    Parameters

    • fields: string[]

    Returns void

build

computeCompleteExpression

  • computeCompleteExpression(): string

computeCompleteExpressionExcept

  • computeCompleteExpressionExcept(except: string): string
  • Return only the expression(s) part(s) of the query, as a string, except the given expression.
    This is used by Facet, to build their group by request with query override.

    Parameters

    • except: string

    Returns string

computeCompleteExpressionParts

computeCompleteExpressionPartsExcept

Properties

actionsHistory

actionsHistory: string

The actions history represents the past actions a user made and is used by the Coveo Machine Learning service to suggest recommendations. It is generated by the page view script (https://github.com/coveo/coveo.analytics.js).

advancedExpression

advancedExpression: ExpressionBuilder

Used to build the advanced part of the query expression.
This part is typically formed of filter expressions generated by components such as facets, external code, etc.

type

{Coveo.ExpressionBuilder}

childField

childField: string

Specifies the childField when doing parent-child loading (See : Folding).

constantExpression

constantExpression: ExpressionBuilder

Used to build the advanced part of the query expression.
This part is similar to advancedExpression, but its content is interpreted as a constant expression by the index and it takes advantage of special caching features.

type

{Coveo.ExpressionBuilder}

context

context: object

The context is a map of key_value that can be used in the Query pipeline in the Coveo platform.

Type declaration

  • [key: string]: any

disjunctionExpression

disjunctionExpression: ExpressionBuilder

Used to build the disjunctive part of the query expression.
When present, this part is evaluated separately from the other expressions and the matching results are merged to those matching expressions, advancedExpression and constantExpression.
The final boolean expression for the query is thus (basic advanced constant) OR (disjunction).

type

{Coveo.ExpressionBuilder}

enableCollaborativeRating

enableCollaborativeRating: boolean

Whether the index should take collaborative rating in account when ranking result (see : ResultRating).

enableDebug

enableDebug: boolean

Whether to enable debug info on the query.
This will return additional information on the resulting JSON response from the Search API.
Mostly: execution report (a detailed breakdown of the parsed and executed query).

enableDidYouMean

enableDidYouMean: boolean

Whether to enable query corrections on this query (see DidYouMean).

enableLowercaseOperators

enableLowercaseOperators: boolean

Whether to enable the support for operator in lowercase (AND OR -> and or).

enablePartialMatch

enablePartialMatch: boolean

Whether to enable partial matching of the basic expression keywords.
By activating this, when the basic expression contains at least IQuery.partialMatchKeywords, items containing only the number of keywords specified by IQuery.partialMatchThreshold will also match the query.
Without this option, items are required to contain all the keywords in order to match the query.
If not specified, this parameter defaults to false.

enableQuerySyntax

enableQuerySyntax: boolean

Whether to enable the special query syntax such as field references for the basic query expression (parameter q). It is equivalent to a No syntax block applied to the basic query expression. If not specified, the parameter defaults to false.

enableQuestionMarks

enableQuestionMarks: boolean

Whether to enable question marks with wildcards.
This enables using the question mark ? character within wildcard expressions.

enableWildcards

enableWildcards: boolean

Whether to enable wildcards on the basic expression keywords.
This enables the wildcard features of the index. Coveo Platform will expand keywords containing wildcard characters to the possible matching keywords to broaden the query.
(see : https://onlinehelp.coveo.com/en/ces/7.0/user/using_wildcards_in_queries.htm).
If not specified, this parameter defaults to false.

excerptLength

excerptLength: number

This specifies the length (in number of characters) of the excerpts generated by the indexer based on the keywords present in the query.
The index includes the top most interesting sentences (in the order they appear in the item) that fit in the specified number of characters.
When not specified, the default value is 200.

expression

expression: ExpressionBuilder

Used to build the basic part of the query expression.
This part typically consists of user-entered content such as query keywords, etc.

type

{Coveo.ExpressionBuilder}

filterField

filterField: string

This specifies a field on which Folding should be performed.
Folding is a kind of duplicate filtering where only the first result with any given value of the field is included in the result set.
It's typically used to return only one result in a conversation, for example when forum posts in a thread are indexed as separate items.

filterFieldRange

filterFieldRange: number

Number of results that should be folded, using the IQuery.filterField.

firstResult

firstResult: number

This is the 0-based index of the first result to return.
If not specified, this parameter defaults to 0.

groupByRequests

groupByRequests: IGroupByRequest[]

This specifies an array of Group By operations that can be performed on the query results to extract facets.

longQueryExpression

longQueryExpression: ExpressionBuilder

The contextual text.
This is the contextual text part of the query. It uses the Coveo Machine Learning service to pick key keywords from the text and add them to the basic expression. This field is mainly used to pass context such a case description, long textual query or any other form of text that might help in refining the query.

maximumAge

maximumAge: number

The maximum age for cached query results, in milliseconds.
If results for the exact same request (including user identities) are available in the in-memory cache, they will be used if they are not older than the specified value.
Otherwise, the query will be sent to the index.

numberOfResults

numberOfResults: number

This is the number of results to return, starting from IQuery.firstResult.
If not specified, this parameter defaults to 10.

parentField

parentField: string

Specifies the parentField when doing parent-child loading (See : Folding).

partialMatchKeywords

partialMatchKeywords: number

The minimum number of keywords needed to activate partial match.
This specifies the minimum number of keywords needed for the partial match feature to activate.
If the basic expression contains less than this number of keywords, no transformation is applied on the query.
If not specified, this parameter defaults to 5.

partialMatchThreshold

partialMatchThreshold: string

The threshold to use for matching items when partial match is enabled.
This specifies the minimum number of query keywords that an item must contain when partial match is enabled. This value can either be an absolute number or a percentage value based on the total number of keywords.
If not specified, this parameter defaults to 50%.

pipeline

pipeline: string

Name of the query pipeline to use.
This specifies the name of the query pipeline to use for the query. If not specified, the default value is default, which means the default query pipeline will be used.

queryFunctions

queryFunctions: IQueryFunction[]

This specifies an array of Query Function operation that will be executed on the results.

rankingFunctions

rankingFunctions: IRankingFunction[]

This specifies an array of Ranking Function operations that will be executed on the results.

recommendation

recommendation: string

This is the ID of the recommendation interface that generated the query.

searchHub

searchHub: string

The hub value set from the Analytics component.
Used for analytics reporting in the Coveo platform.

sortCriteria

sortCriteria: string

This specifies the sort criterion(s) to use to sort results. If not specified, this parameter defaults to relevancy.
Possible values are :
-- relevancy : This uses all the configured ranking weights as well as any specified ranking expressions to rank results.
-- dateascending / datedescending Sort using the value of the @date field, which is typically the last modification date of an item in the index.
-- qre : Sort using only the weights applied through ranking expressions. This is much like using relevancy except that automatic weights based on keyword proximity etc, are not computed.
-- nosort : Do not sort the results. The order in which items are returned is essentially random.
-- @field ascending / @field descending Sort using the value of a custom field.

tab

tab: string

The tab value set from the Tab component.

Hierarchy

  • QueryBuilder