import type { SearchEngine } from '../../../app/search-engine/search-engine.js'; import { type Subscribable } from '../../controller/headless-controller.js'; import type { FacetOptions } from '../../facets/facet/headless-facet-options.js'; export interface FieldSuggestionsValue { /** * The custom field suggestion display name, as specified in the `captions` argument of the `FieldSuggestion` controller. */ displayValue: string; /** * The original field value, as retrieved from the field in the index. */ rawValue: string; /** * An estimated number of result items matching both the current query and * the filter expression that would get generated if this field suggestion was selected. */ count: number; } /** * The state of the `FieldSuggestions` controller. * * @group Controllers * @category FieldSuggestions */ export interface FieldSuggestionsState { /** * The field suggestions. */ values: FieldSuggestionsValue[]; /** * Whether the request for field suggestions is in progress. */ isLoading: boolean; /** * Whether more field suggestions are available. */ moreValuesAvailable: boolean; /** * The query used to request field suggestions. */ query: string; } /** * The `FieldSuggestions` controller provides query suggestions based on a particular facet field. * * For example, you could use this controller to provide auto-completion suggestions while the end user is typing an item title. * * This controller is a wrapper around the basic facet controller search functionality, and thus exposes similar options and properties. * * Example: [field-suggestions.fn.tsx](https://github.com/coveo/ui-kit/blob/main/samples/headless/search-react/src/components/field-suggestions/specific-field/field-suggestions.fn.tsx) * * @group Controllers * @category FieldSuggestions */ export interface FieldSuggestions extends Subscribable { /** * Requests field suggestions based on a query. * * @param text - The query to search. */ updateText(text: string): void; /** * Shows more field suggestions for the current query. */ showMoreResults(): void; /** * Requests field suggestions based on a query. */ search(): void; /** * Filters the search using the specified value. * * If a facet exists with the configured `facetId`, selects the corresponding facet value. * * @param value - The field suggestion for which to select the matching facet value. */ select(value: FieldSuggestionsValue): void; /** * Filters the search using the specified value, deselecting others. * * If a facet exists with the configured `facetId`, selects the corresponding facet value while deselecting other facet values. * * @param value - The field suggestion for which to select the matching facet value. */ singleSelect(value: FieldSuggestionsValue): void; /** * Resets the query and empties the suggestions. */ clear(): void; /** * Updates the captions of field suggestions. * * @param captions - A dictionary that maps field values to field suggestion display names. */ updateCaptions(captions: Record): void; state: FieldSuggestionsState; } export interface FieldSuggestionsOptions { /** * The options used to register the facet used by the field suggestions controller. */ facet: FacetOptions; } export interface FieldSuggestionsProps { /** * The options for the `FieldSuggestions` controller. */ options: FieldSuggestionsOptions; } /** * Creates a `FieldSuggestions` controller instance. * * This controller initializes a facet under the hood, but exposes state and methods that are relevant for suggesting field values based on a query. * It's important not to initialize a facet with the same `facetId` but different options, because only the options of the controller which is built first will be taken into account. * * @param engine The headless engine. * @param props The configurable `FieldSuggestions` controller properties. * @returns A `FieldSuggestions` controller instance. * * @group Controllers * @category FieldSuggestions */ export declare function buildFieldSuggestions(engine: SearchEngine, props: FieldSuggestionsProps): FieldSuggestions;