# Coveo SearchInterface Component (CoveoSearchInterface)

The SearchInterface component is the root and main component of your Coveo search interface. You should place all other Coveo components inside the SearchInterface component.

It is also on the HTMLElement of the SearchInterface component that you call the init function.

It is advisable to specify a unique HTML `id` attribute for the SearchInterface component in order to be able to reference it easily.

Example:

    <head>

    [ ... ]

    <script>
      document.addEventListener('DOMContentLoaded', function() {

        [ ... ]
        // The init function is called on the SearchInterface element, in this case, the body of the page.
        Coveo.init(document.body);

        [ ... ]

        });
    </script>

    [ ... ]
    </head>

    <!-- Specifying a unique HTML id attribute for the SearchInterface component is good practice. -->
    <body id='search' class='CoveoSearchInterface' [ ... other options ... ]>

      [ ... ]

      <!-- You should place all other Coveo components here, inside the SearchInterface component. -->

      [ ... ]

    </body>

## Index

### Methods

- attachComponent
- debugInfo
- detachComponent
- detachComponentsInside
- disable
- enable
- getBindings
- getComponents
- getQueryContext

### Properties

- disabled
- logger
- responsiveComponents
- ID

### Component Options

- allowQueriesWithoutKeywords
- autoTriggerQuery
- enableAutomaticResponsiveMode
- enableCollaborativeRating
- enableDebugInfo
- enableDuplicateFiltering
- enableHistory
- enableScrollRestoration
- excerptLength
- expression
- filterField
- firstLoadingAnimation
- hideUntilFirstQuery
- maximumAge
- modalContainer
- pipeline
- responsiveMediumBreakpoint
- responsiveMode
- responsiveSmallBreakpoint
- resultsPerPage
- searchPageUri
- timezone
- useLocalStorageForHistory

### Constructors

- constructor

## Methods

### attachComponent

- attachComponent(type: string, component: BaseComponent): void

- - Defined in ui/SearchInterface/SearchInterface.ts :617

  Attaches a component to the search interface. This allows the search interface to easily list and iterate over its components.

  #### Parameters

  - ##### type: string

    Normally, the component type is a unique identifier without the `Coveo` prefix (e.g., `CoveoFacet` -> `Facet`, `CoveoPager` -> `Pager`, `CoveoQuerybox` -> `Querybox`, etc.).

  - ##### component: BaseComponent

    The component instance to attach.

  #### Returns void

### debugInfo

- debugInfo(): any

- Inherited from BaseComponent.debugInfo

  - Defined in ui/Base/BaseComponent.ts :41

  Return the debug info about this component.

  #### Returns any

### detachComponent

- detachComponent(type: string, component: BaseComponent): void

- - Defined in ui/SearchInterface/SearchInterface.ts :627

  Detaches a component from the search interface.

  #### Parameters

  - ##### type: string

    Normally, the component type is a unique identifier without the `Coveo` prefix (e.g., `CoveoFacet` -> `Facet`, `CoveoPager` -> `Pager`, `CoveoQuerybox` -> `Querybox`, etc.).

  - ##### component: BaseComponent

    The component instance to detach.

  #### Returns void

### detachComponentsInside

- detachComponentsInside(element: HTMLElement): void

- - Defined in ui/SearchInterface/SearchInterface.ts :714

  Detaches from the SearchInterface every component that is inside the given element.

  #### Parameters

  - ##### element: HTMLElement

  #### Returns void

### disable

- disable(): void

- Inherited from BaseComponent.disable

  - Defined in ui/Base/BaseComponent.ts :52

  Disable the component. Normally this means that the component will not execute handlers for the framework events (query events, for example). Components are enabled by default on creation.

  #### Returns void

### enable

- enable(): void

- Inherited from BaseComponent.enable

  - Defined in ui/Base/BaseComponent.ts :61

  Enable the component. Normally this means that the component will execute handlers for the framework events (query events, for example). Components are enabled by default on creation.

  #### Returns void

### getBindings

- getBindings(): object

- - Defined in ui/SearchInterface/SearchInterface.ts :639

  Returns the bindings, or environment, for the current component.

  #### Returns object

### getComponents

- getComponents<T>(type: string): T[]

- - Defined in ui/SearchInterface/SearchInterface.ts :693

  Gets all the components of a given type.

  #### Type parameters

  - #### T

  #### Parameters

  - ##### type: string

    Normally, the component type is a unique identifier without the `Coveo` prefix (e.g., `CoveoFacet` -> `Facet`, `CoveoPager` -> `Pager`, `CoveoQuerybox` -> `Querybox`, etc.).

  #### Returns T[]

### getQueryContext

- getQueryContext(): Context

- - Defined in ui/SearchInterface/SearchInterface.ts :665

  Gets the query context for the current search interface.

  If the search interface has performed at least one query, it will try to resolve the context from the last query sent to the Coveo Search API.

  If the search interface has not performed a query yet, it will try to resolve the context from any avaiable PipelineContext component.

  If multiple PipelineContext components are available, it will merge all context values together.

  Note: Having multiple PipelineContext components in the same search interface is not recommended, especially if some context keys are repeated across those components.

  If no context is found, returns `undefined`

  #### Returns Context

## Properties

### disabled

disabled: boolean

Inherited from BaseComponent.disabled

- Defined in ui/Base/BaseComponent.ts :23

A disabled component will not participate in the query, or listen to ComponentEvents.

type

  {boolean}

### logger

logger: Logger

Inherited from BaseComponent.logger

- Defined in ui/Base/BaseComponent.ts :18

Allows component to log in the dev console.

### responsiveComponents

responsiveComponents: ResponsiveComponents

- Defined in ui/SearchInterface/SearchInterface.ts :528

Allows to get and set the different breakpoints for mobile and tablet devices.

This is useful, amongst other, for Facet, Tab and ResultList

### Static ID

ID: string

Inherited from BaseComponent.ID

- Defined in ui/Base/BaseComponent.ts :28

The static ID that each component needs in order to be identified.
For example, SearchButton -> static ID: SearchButton -> className: CoveoSearchButton

## Component Options

### allowQueriesWithoutKeywords

allowQueriesWithoutKeywords: boolean

- Defined in ui/SearchInterface/SearchInterface.ts :337

Specifies if the search interface should perform queries when no keywords are entered by the end user.

When this option is set to true, the interface will initially only load with the search box, as long as you have a search box component in your interface.

Once the user submits a query, the full search interface loads to display the results.

When using the Coveo for Salesforce Free edition, this option is automatically set to false, and should not be changed.

This option interacts closely with the SearchInterface.options.autoTriggerQuery option, as the automatic query is not triggered when there are no keywords.

It also modifies the IQuery.allowQueriesWithoutKeywords query parameter.

Default value is `true`, except in Coveo for Salesforce Free edition in which it is `false`.

Default

  `true`

Markup configuration example(s) :

    data-allow-queries-without-keywords='true'
    data-allow-queries-without-keywords='false'

### autoTriggerQuery

autoTriggerQuery: boolean

- Defined in ui/SearchInterface/SearchInterface.ts :321

Specifies whether to trigger the first query automatically when the page finishes loading.

Default value is `true`.

Default

  `true`

Markup configuration example(s) :

    data-auto-trigger-query='true'
    data-auto-trigger-query='false'

### enableAutomaticResponsiveMode

enableAutomaticResponsiveMode: boolean

- Defined in ui/SearchInterface/SearchInterface.ts :179

Specifies whether to enable automatic responsive mode (i.e., automatically placing Facet and Tab components in dropdown menus under the search box when the width of the SearchInterface HTML element reaches or falls behind a certain pixel threshold).

You might want to set this option to `false` if automatic responsive mode does not suit the specific design needs of your implementation.

Note:

> If this option is `true`, you can also specify whether to enable responsive mode for Facet components (see {@link Facet.options.enableResponsiveMode}) and for Tab components (see Tab.options.enableResponsiveMode).

> In addition, you can specify the label you wish to display on the dropdown buttons (see {@link Facet.options.dropdownHeaderLabel} and Tab.options.dropdownHeaderLabel).

Default value is `true`.

Default

  `true`

Markup configuration example(s) :

    data-enable-automatic-responsive-mode='true'
    data-enable-automatic-responsive-mode='false'

### enableCollaborativeRating

enableCollaborativeRating: boolean

- Defined in ui/SearchInterface/SearchInterface.ts :377

Note:

> The Coveo Cloud V2 platform does not support collaborative rating. Therefore, this option is obsolete in Coveo Cloud V2.

Specifies whether to enable collaborative rating, which you can leverage using the `ResultRating` component.

Setting this option to `true` has no effect unless collaborative rating is also enabled on your Coveo index.

Default value is `false`.

Default

  `false`

Markup configuration example(s) :

    data-enable-collaborative-rating='true'
    data-enable-collaborative-rating='false'

### enableDebugInfo

enableDebugInfo: boolean

- Defined in ui/SearchInterface/SearchInterface.ts :363

Specifies whether to enable the feature that allows the end user to ALT + double click any result to open a debug page with detailed information about all properties and fields for that result.

Enabling this feature causes no security concern; the entire debug information is always visible to the end user through the browser developer console or by calling the Coveo API directly.

Default value is `true`.

Default

  `true`

Markup configuration example(s) :

    data-enable-debug-info='true'
    data-enable-debug-info='false'

### enableDuplicateFiltering

enableDuplicateFiltering: boolean

- Defined in ui/SearchInterface/SearchInterface.ts :388

Whether to filter out duplicates, so that items resembling one another only appear once in the query results.

Notes:

- Two items must be at least 85% similar to one another to be considered duplicates.
- When a pair of duplicates is found, only the higher-ranked item of the two is kept in the result set.
- Enabling this feature can make the total result count less precise, as only the requested page of query results is submitted to duplicate filtering.
- This option can also be explicitly set on the `Tab` component. When this is the case, the `Tab` configuration prevails.

Default

  `false`

Markup configuration example(s) :

    data-enable-duplicate-filtering='true'
    data-enable-duplicate-filtering='false'

### enableHistory

enableHistory: boolean

- Defined in ui/SearchInterface/SearchInterface.ts :158

Whether to allow the end user to navigate search history using the Back and Forward buttons of the browser.

If this option is set to `true`, the state of the current query will be saved in the hash portion of the URL when the user submits the query.

Example:

> If the `enableHistory` option is `true` and the current query is `foobar`, the SearchInterface component saves `q=foobar` in the URL hash when the user submits the query.

Note: Avoid setting this option to `true` on a search interface that relates to a Coveo for Salesforce Full Search or Insight Panel component, otherwise the component won't initialize correctly.

Default

  `false`

Markup configuration example(s) :

    data-enable-history='true'
    data-enable-history='false'

### enableScrollRestoration

enableScrollRestoration: boolean

- Defined in ui/SearchInterface/SearchInterface.ts :488

Specifies whether to restore the last scroll position when navigating back to the search interface.

Default

  `false`

Available since

  March 2020 Release (v2.8521)

Markup configuration example(s) :

    data-enable-scroll-restoration='true'
    data-enable-scroll-restoration='false'

### excerptLength

excerptLength: number

- Defined in ui/SearchInterface/SearchInterface.ts :212

Specifies the number of characters to get at query time to create an excerpt of the result.

This setting is global and cannot be modified on a per-result basis.

See also the Excerpt component.

Default value is `200`. Minimum value is `0`.

Minimum

  `0`

Default

  `200`

Markup configuration example(s) :

    data-excerpt-length='10'

### expression

expression: string

- Defined in ui/SearchInterface/SearchInterface.ts :229

Specifies an expression to add to each query.

You might want to use this options to add a global filter to your entire search interface that applies for all tabs.

You should not use this option to address security concerns (it is JavaScript, after all).

Note:

> It also is possible to set this option separately for each Tab component (see Tab.options.expression).

Default value is `''`.

Default

  ``

Markup configuration example(s) :

    data-expression='foo'

### filterField

filterField: IFieldOption

- Defined in ui/SearchInterface/SearchInterface.ts :246

Specifies the name of a field to use as a custom filter when executing the query (also referred to as "folding").

Setting a value for this option causes the index to return only one result having any particular value inside the filter field. Any other matching result is "folded" inside the childResults member of each JSON query result.

This feature is typically useful with threaded conversations to include only one top-level result per conversation. Thus, the field you specify for this option will typically be value unique to each thread that is shared by all items (e.g., posts, emails, etc) in the thread.

For more advanced features, see the Folding component.

Default value is the empty string (`''`).

Default

  ``

Markup configuration example(s) :

    data-filter-field='@foo'

### firstLoadingAnimation

firstLoadingAnimation: HTMLElement

- Defined in ui/SearchInterface/SearchInterface.ts :312

Specifies the animation that you wish to display while your interface is loading.

You can either specify the CSS selector of an HTML element that matches the default CSS class (`coveo-first-loading-animation`), or add `-selector` to the markup attribute of this option to specify the CSS selector of an HTML element that matches any CSS class.

See also the hideUntilFirstQuery option.

Examples:

In this first case, the SearchInterface uses the HTML element whose `id` attribute is `MyAnimation` as the loading animation only if the `class` attribute of this element also matches `coveo-first-loading-animation`. Default loading animation CSS, which you can customize as you see fit, applies to this HTML element.

    <div class='CoveoSearchInterface' data-first-loading-animation='#MyAnimation'>
      <div id='MyAnimation' class='coveo-first-loading-animation'>
        <!-- ... -->
      </div>
      <!-- ... -->
    </div>

In this second case, the SearchInterface uses the HTML element whose `id` attribute is `MyAnimation` as the loading animation no matter what CSS class it matches. However, if the `class` attribute of the HTML element does not match `coveo-first-loading-animation`, no default loading animation CSS applies to this HTML element. Normally, you should only use `data-first-loading-animation-selector` if you want to completely override the default loading animation CSS.

    <div class='CoveoSearchInterface' data-first-loading-animation-selector='#MyAnimation'>
      <div id='MyAnimation' class='my-custom-loading-animation-class'>
        <!-- ... -->
      </div>
      <!-- ... -->
    </div>

By default, the loading animation is a Coveo CSS animation (which you can customize with CSS).

deprecated

  This option is exposed for legacy reasons. Since the July 2017 Release (v2.2900.23), the loading animation is composed of placeholders, making this option is obsolete.

### hideUntilFirstQuery

hideUntilFirstQuery: boolean

- Defined in ui/SearchInterface/SearchInterface.ts :265

Specifies whether to display a loading animation before the first query successfully returns.

Note:

> If you do not set this options to `false`, the loading animation will still run until the first query successfully returns even if the autoTriggerQuery option is `false`.

See also the firstLoadingAnimation option.

Default value is `true`.

deprecated

  This option is exposed for legacy reasons. Since the July 2017 Release (v2.2900.23), the loading animation is composed of placeholders, making this option is obsolete.

Markup configuration example(s) :

    data-hide-until-first-query='true'
    data-hide-until-first-query='false'

### maximumAge

maximumAge: number

- Defined in ui/SearchInterface/SearchInterface.ts :425

Specifies the maximum age (in milliseconds) that cached query results can have to still be usable as results instead of performing a new query on the index. The cache is located in the Coveo Search API (which resides between the index and the search interface).

If cached results that are older than the age you specify in this option are available, the framework will not use these results; it will rather perform a new query on the index.

On high-volume public web sites, specifying a higher value for this option can greatly improve query response time at the cost of result freshness.

Note:

> It also is possible to set this option separately for each Tab component (see Tab.options.maximumAge).

Default value is `undefined`, which means that the search interface lets the Coveo Search API determine the maximum cache age. This is typically equivalent to 30 minutes (see maximumAge).

Markup configuration example(s) :

    data-maximum-age='10'

### modalContainer

modalContainer: HTMLElement

- Defined in ui/SearchInterface/SearchInterface.ts :510

Specifies the HTMLElement to which Modals components of the search interface will be attached to. You can either specify a CSS selector or pass an HTMLElement in the options when calling Coveo.init.

Default value is `element.ownerDocument.body`.

Example in attribute:

    <div class="CoveoSearchInterface" data-modal-container="#my-modal-container"></div>

Example in init options:

    var myContainer = document.getElementById('my-modal-container');
    Coveo.init(root, {
      SearchInterface: {
        modalContainer: myContainer
      }
    });

### pipeline

pipeline: string

- Defined in ui/SearchInterface/SearchInterface.ts :403

Specifies the name of the query pipeline to use for the queries.

You can specify a value for this option if your index is in a Coveo Cloud organization in which pipelines have been created (see Adding and Managing Query Pipelines).

Note:

> It also is possible to set this option separately for each Tab component (see Tab.options.pipeline).

Default value is `undefined`, which means that the search interface uses the default pipeline.

Markup configuration example(s) :

    data-pipeline='foo'

### responsiveMediumBreakpoint

responsiveMediumBreakpoint: number

- Defined in ui/SearchInterface/SearchInterface.ts :441

Specifies the search interface width that should be considered "medium" size, in pixels.

When the width of the window/device that displays the search page reaches or falls short of this threshold (but still exceeds the responsiveSmallBreakpoint value), the search page layout will change so that, for instance, facets within the element that has the coveo-facet-column class will be accessible from a dropdown menu on top of the result list rather than being fully rendered next to the result list.

This option is only taken into account when enableAutomaticResponsiveMode is set to true.

Default value is `800`.

Only effective when

  `enableAutomaticResponsiveMode` is set to `true`

Markup configuration example(s) :

    data-responsive-medium-breakpoint='10'

### responsiveMode

responsiveMode: "auto" | "small" | "medium" | "large"

- Defined in ui/SearchInterface/SearchInterface.ts :468

Specifies the search interface responsive mode that should be used.

When the mode is auto, the width of the window/device that displays the search page is used to determine which layout the search page should use (see enableAutomaticResponsiveMode, responsiveMediumBreakpoint and [responsiveSmallBreakpointSearchInterface.options.responsiveSmallBreakpoint])

When it's not on auto, the width is ignored and the the layout used depends on this option (e.g. If set to "small", then the search interface layout will be the same as if it was on a narrow window/device)

Default

  `auto`

### responsiveSmallBreakpoint

responsiveSmallBreakpoint: number

- Defined in ui/SearchInterface/SearchInterface.ts :454

Specifies the search interface width that should be considered "small" size, in pixels.

When the width of the window/device that displays the search page reaches or falls short of this threshold, the search page layout will change so that, for instance, some result list layouts which are not suited for being rendered on a small screen/area will be disabled.

This option is only taken into account when enableAutomaticResponsiveMode is set to true.

Default value is `480`.

Only effective when

  `enableAutomaticResponsiveMode` is set to `true`

Markup configuration example(s) :

    data-responsive-small-breakpoint='10'

### resultsPerPage

resultsPerPage: number

- Defined in ui/SearchInterface/SearchInterface.ts :201

Specifies the number of results to display on each page.

For more advanced features, see the ResultsPerPage component.

Note:

> When the ResultsPerPage component is present in the page, this option gets overridden and is useless.

Default value is `10`. Minimum value is `0`.

Minimum

  `0`

Default

  `10`

Markup configuration example(s) :

    data-results-per-page='10'

### searchPageUri

searchPageUri: string

- Defined in ui/SearchInterface/SearchInterface.ts :431

Specifies the search page you wish to navigate to when instantiating a standalone search box interface.

Default value is `undefined`, which means that the search interface does not redirect.

Markup configuration example(s) :

    data-search-page-uri='foo'

### timezone

timezone: string

- Defined in ui/SearchInterface/SearchInterface.ts :353

Specifies the timezone in which the search interface is loaded. This allows the index to recognize some special query syntax.

This option must have a valid IANA zone info key (AKA the Olson time zone database) as its value.

Example: `America/New_York`.

By default, the search interface allows a library to try to detect the timezone automatically.

Markup configuration example(s) :

    data-timezone='foo'

### useLocalStorageForHistory

useLocalStorageForHistory: boolean

- Defined in ui/SearchInterface/SearchInterface.ts :188

Specifies whether to save the interface state in the local storage of the browser.

You might want to set this option to `true` for reasons specifically important for your implementation.

Default value is `false`.

Default

  `false`

Markup configuration example(s) :

    data-use-local-storage-for-history='true'
    data-use-local-storage-for-history='false'

## Constructors

### constructor

- new SearchInterface(element: HTMLElement, options?: ISearchInterfaceOptions, analyticsOptions?: any, _window?: Window): SearchInterface

- - Defined in ui/SearchInterface/SearchInterface.ts :536

  Creates a new SearchInterface. Initialize various singletons for the interface (e.g., usage analytics, query controller, state model, etc.). Binds events related to the query.

  #### Parameters

  - ##### element: HTMLElement

    The HTMLElement on which to instantiate the component. This cannot be an `HTMLInputElement` for technical reasons.

  - ##### Optional options: ISearchInterfaceOptions

    The options for the SearchInterface.

  - ##### Optional analyticsOptions: any

    The options for the Analytics component. Since the Analytics component is normally global, it needs to be passed at initialization of the whole interface.

  - ##### Default value _window: Window = window

    The window object for the search interface. Used for unit tests, which can pass a mock. Default is the global window object.

  #### Returns SearchInterface

### Implements

- IComponentBindings