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 interpret the AND, NOT, OR, and NEAR keywords in the basic expression as query operators, even if those keywords are in lowercase.

Setting this attribute to true has no effect unless enableQuerySyntax is also true.

Note:

Normally, the enableLowercaseOperators option of the Querybox component determines the value of this attribute during the initialization of the search page.

enablePartialMatch

enablePartialMatch: boolean

Whether to automatically convert the basic expression to a partial match expression if it contains at least a certain number of keywords (see partialMatchKeywords), so that items containing at least a certain subset of those keywords (see partialMatchThreshold) will match the query.

Note:

Normally, the enablePartialMatch option of the Querybox component determines the value of this attribute during the initialization of the search page.

enableQuerySyntax

enableQuerySyntax: boolean

Whether to interpret special query syntax (e.g., @objecttype=message) in the basic expression (see Coveo Query Syntax Reference).

See also enableLowercaseOperators.

Note:

Normally, the enableQuerySyntax option of the Querybox component determines the value of this attribute during the initialization of the search page. End user preferences can also modify the value of this attribute.

Default value is false

enableQuestionMarks

enableQuestionMarks: boolean

Whether to interpret question mark characters (?) in the basic expression keywords (see Using Wildcards in Queries.

Setting this attribute to true has no effect unless enableWildcards is also true.

Note:

Normally, the enableQuestionMarks option of the Querybox component determines the value of this attribute during the initialization of the search page.

enableWildcards

enableWildcards: boolean

Whether to interpret wildcard characters (*) in the basic expression keywords.

Setting this attribute to true enables the wildcards features of the index, effectively expanding keywords containing wildcard characters (*) to the possible matching keywords in order to broaden the query (see Using Wildcards in Queries).

See also enableQuestionMarks.

Note:

Normally, the enableWildcards option of the Querybox component determines the value of this attribute during the initialization of the search page.

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 that need to be present in the basic expression to convert it to a partial match expression.

The value of this attribute has no meaning unless enablePartialMatch is true.

See also partialMatchThreshold.

Note:

Normally, the partialMatchKeywords option of the Querybox component determines the value of this attribute during the initialization of the search page.

partialMatchThreshold

partialMatchThreshold: string

An absolute or relative (percentage) value indicating the minimum number of partial match expression keywords an item must contain to match the query.

The value of this attribute has no meaning unless enablePartialMatch is true.

See also partialMatchKeywords.

Note:

Normally, the partialMatchThreshold option of the Querybox component determines the value of this attribute during the initialization of the search page.

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