Coveo SimpleFilter Component (CoveoSimpleFilter)

The SimpleFilter component displays a dropdown menu containing field values which the end user can select to filter the query results.

The list of available field values in the dropdown menu can either be static (defined through the values option), or dynamic (automatically obtained through a GroupByRequest operation performed at the same time as the main query).

Available since

November 2017 Release (v2.3477.9)

Index

Methods

closeContainer

  • closeContainer(): void

debugInfo

  • debugInfo(): any

deselectValue

  • deselectValue(value: string): void

disable

  • disable(): void
  • 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
  • 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

getSelectedCaptions

  • getSelectedCaptions(): string[]
  • Gets the captions of the currently selected field values in the SimpleFilter.

    Returns string[]

    An array containing the selected captions.

getValueCaption

  • getValueCaption(value: string): string
  • Gets the caption of a specific field value.

    Parameters

    • value: string

      The field value whose caption the method should attempt to get.

    Returns string

    The value caption, if available; the original value otherwise.

getValueContainer

  • getValueContainer(): Dom

openContainer

  • openContainer(): void

resetSimpleFilter

  • resetSimpleFilter(): void

selectValue

  • selectValue(value: string, triggerQuery?: boolean): void
  • Selects the specified value. Also triggers a query, by default.

    Parameters

    • value: string

      The value to select.

    • Default value triggerQuery: boolean = true

      true by default. If set to false, the method triggers no query.

    Returns void

toggleContainer

  • toggleContainer(): void

toggleValue

  • toggleValue(value: string): void
  • Selects or un-selects the specified value, depending on its current state.

    Parameters

    • value: string

      The value whose state the method should toggle.

    Returns void

Static get

  • get(element: HTMLElement, componentClass?: any, noThrow?: boolean): BaseComponent
  • Get the bound component to the given HTMLElement. Throws an assert if the HTMLElement has no component bound, unless using the noThrow argument.
    If there is multiple component bound to the current HTMLElement, you must specify the component class.

    Parameters

    • element: HTMLElement

      HTMLElement for which to get the bound component.

    • Optional componentClass: any

      Optional component class. If the HTMLElement has multiple components bound, you must specify which one you are targeting.

    • Optional noThrow: boolean

      Boolean option to tell the method to not throw on error.

    Returns BaseComponent

Properties

bind

Allows the component to bind events and execute them only when it is enabled.

type

{Coveo.ComponentEvents}

componentOptionsModel

componentOptionsModel: ComponentOptionsModel

Contains the state of options for different components. Mainly used by ResultLink.

componentStateModel

componentStateModel: ComponentStateModel

Contains the state of different components (enabled vs disabled). Allows to get/set values. Triggers component state event when modified. Each component can listen to those events.

disabled

disabled: boolean

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

type

{boolean}

logger

logger: Logger

Allows component to log in the dev console.

queryController

queryController: QueryController

Contains the singleton that allows to trigger queries.

queryStateModel

queryStateModel: QueryStateModel

Contains the state of the query. Allows to get/set values. Trigger query state event when modified. Each component can listen to those events.

root

root: HTMLElement

A reference to the root HTMLElement (the SearchInterface).

searchInterface

searchInterface: SearchInterface

A reference to the root of every component, the SearchInterface.

Static ID

ID: string

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

Accessors

usageAnalytics

Component Options

enableClearButton

enableClearButton: boolean

Whether to show a button to clear all selected values.

Default

false

Available since

March 2020 Release (v2.8521)

Markup configuration example(s) :
data-enable-clear-button='true'
data-enable-clear-button='false'

field

Specifies the field whose values the SimpleFilter should output result filters from.

Specifying a value for this option is required for the SimpleFilter component to work.

Required

Specifying a value for this option is required for the component to work

Markup configuration example(s) :
data-field='@foo'

maximumNumberOfValues

maximumNumberOfValues: number

Specifies the maximum number of field values to display in the SimpleFilter dropdown menu.

Default value is 5. Minimum value is 0.

Minimum

0

Default

5

Markup configuration example(s) :
data-maximum-number-of-values='10'

sortCriteria

sortCriteria: "occurrences" | "score" | "alphaascending" | "alphadescending" | "computedfieldascending" | "computedfielddescending" | "chisquare" | "nosort"

string? The sort criteria to use.

Default: score

Allowed values:

score: sort using the score value which is computed from the number of occurrences of a field value, as well as from the position where query result items having this field value appear in the ranked query result set. When using this sort criterion, a field value with 100 occurrences might appear after one with only 10 occurrences, if the occurrences of the latter field value tend to appear higher in the ranked query result set.

occurrences: sort by number of occurrences, with field values having the highest number of occurrences appearing first.

alphaascending/alphadescending: sort alphabetically on the field values.

chisquare: sort based on the relative frequency of field values in the query result set compared to their frequency in the entire index. This means that a field value that does not appear often in the index, but does appear often in the query result set will tend to appear higher.

Available since

July 2019 Release (v2.6459)

title

title: string

Specifies the title to display for the SimpleFilter.

Default value is the localized string for NoTitle.

Markup configuration example(s) :
data-title='foo'

valueCaption

valueCaption: any

Specifies a JSON object describing a mapping of SimpleFilter values to their desired captions.

Examples:

  • You can set the option in the 'init' call: `javascript var myValueCaptions = { "txt" : "Text files", "html" : "Web page", [ ... ] };

Coveo.init(document.querySelector("#search"), { SimpleFilter : { valueCaption : myValueCaptions } });


* Or before the `init` call, using the <a href="simplefilter.html#options">'options'</a> top-level function:
```javascript
Coveo.options(document.querySelector("#search"), {
  SimpleFilter : {
    valueCaption : myValueCaptions
  }
});
  • Or directly in the markup:
    <!-- Ensure that the double quotes are properly handled in `data-value-caption`. -->
    <div class='CoveoSimpleFilter' data-field='@myotherfield' data-value-caption='{"txt":"Text files","html":"Web page"}'></div>
    

values

values: string[]

Specifies a static list of field values to display in the SimpleFilter dropdown menu.

This option is undefined by default, which means that the component generates a dynamic list of field values by performing a GroupByRequest operation at the same time as the main query.

Constructors

constructor

  • Creates a new SimpleFilter component. Binds multiple query events as well.

    Parameters

    • element: HTMLElement

      the HTMLElement on which to instantiate the component.

    • options: ISimpleFilterOptions

      The options for the SimpleFilter component.

    • Optional bindings: IComponentBindings

      The bindings that the component requires to function normally.

    Returns SimpleFilter