ResultList

The ResultList headless controller offers a high-level interface for designing a common result list UI controller.

Methods

fetchMoreResults

Using the same parameters as the last successful query, fetch another batch of results. Particularly useful for infinite scrolling, for example.

subscribe

Adds a callback that will be called on state change.

Parameters

  • listener: () ⇒ void

    A callback to be invoked on state change.

Returns Unsubscribe: An unsubscribe function to remove the listener.

Attributes

state

The state of the ResultList controller.

Properties

  • results: Result[]

    The results of the last executed search.

  • searchUid: string

    The unique identifier of the last executed search.

  • firstSearchExecuted: boolean

    Determines if a first search has been executed.

  • hasResults: boolean

    Determines if there are results available for the last executed query.

  • isLoading: boolean

    Determines if a search is in progress.

Initialize

buildResultList

Creates a ResultList controller instance.

Parameters

  • engine: Engine<SearchSection & ConfigurationSection>

    The headless engine.

  • props?: ResultListProps

    The configurable ResultList properties.

Returns ResultList

ResultListProps

The configurable ResultList properties.

Properties

ResultListOptions

The options for the ResultList controller.

Properties

  • fieldsToInclude?: string[]

    A list of indexed fields to include in the objects returned by the result list. These results are included in addition to the default fields. If this is left empty only the default fields are included.

Raw

Properties

  • [key: string]: unknown

    Custom keys that depend on the documents in the index.

Result

Properties

  • absentTerms: string[]

    The basic query expression terms which this query result item does not match. Note: This property is populated by terms from the query pipeline-processed q value (not from the original q value).

  • clickUri: string

    The hyperlinkable item URI. Notes: Use the clickUri value when you want to create hyperlinks to the item, rather than the uri or printableUri value.

  • excerpt: string

    The contextual excerpt generated for the item (see the excerptLength query parameter).

  • excerptHighlights: string[]

    The length and offset of each word to highlight in the item excerpt string.

  • firstSentences: string

    The first sentences retrieved from the item (see the retrieveFirstSentences query parameter).

  • firstSentencesHighlights: string[]

    The length and offset of each word to highlight in the item firstSentences string.

  • flags: string

    The flags that are set on the item by the index. Distinct values are separated by semicolons.

  • hasHtmlVersion: boolean

    Whether the index contains an HTML version of this item.

  • isRecommendation: boolean

    Whether the item score was boosted as a Coveo ML recommendation.

  • isTopResult: boolean

    Whether the item score was boosted by a featured result rule in the query pipeline.

  • percentScore: number

    The item ranking score expressed as a percentage (see the sortCriteria and rankingFunctions query parameters).

  • printableUri: string

    The human readable item URI. Note: Avoid using the printableUri value to create hyperlinks to the item. Use the clickUri value instead.

  • printableUriHighlights: string

    The length and offset of each word to highlight in the item printableUri string.

  • rankingInfo: string | null

    The raw debug information generated by the index to detail how the item was ranked. This property is null unless the debug query parameter is set to true.

  • rankingModifier?: string

    If applicable, represents the type of ranking modification that was applied to this result.

  • raw: Raw

    The values of the fields which were retrieved for this item (see the fieldsToInclude and fieldsToExclude query parameters).

  • score: number

    The total ranking score computed for the item (see the sortCriteria and rankingFunctions query parameters).

  • summary: null

    The item summary (see the summaryLength query parameter).

  • summaryHighlights: string[]

    The length and offset of each word to highlight in the item summary string.

  • title: string

    Contains the title of the item.

  • titleHighlights: string[]

    The length and offset of each word to highlight in the item title string.

  • uniqueId: string

    The unique item identifier. You should consider the uniqueId value as an opaque string.

  • uri: string

    The item URI. Notes: Avoid using the uri value to create hyperlinks to the item. Use the clickUri value instead.

Unsubscribe

Call signatures

  • (): void

Example Implementation

result-list.fn.tsx

import {useEffect, useState, FunctionComponent} from 'react';
import {
  buildResultList,
  ResultList as HeadlessResultList,
} from '@coveo/headless';
import {engine} from '../../engine';
import {ResultLink} from './result-link';
 
interface ResultListProps {
  controller: HeadlessResultList;
}
 
export const ResultList: FunctionComponent<ResultListProps> = (props) => {
  const {controller} = props;
  const [state, setState] = useState(controller.state);
 
  useEffect(() => controller.subscribe(() => setState(controller.state)), []);
 
  if (!state.results.length) {
    return <div>No results</div>;
  }
 
  return (
    <div>
      <ul style={{textAlign: 'left'}}>
        {state.results.map((result) => (
          <li key={result.uniqueId}>
            <article>
              <h2>
                {/* Make sure to log analytics when the result link is clicked. */}
                <ResultLink result={result}>{result.title}</ResultLink>
              </h2>
              <p>{result.excerpt}</p>
            </article>
          </li>
        ))}
      </ul>
    </div>
  );
};
 
// usage
 
const controller = buildResultList(engine);
 
<ResultList controller={controller} />;
Recommended Articles