Movatterモバイル変換


[0]ホーム

URL:


Loading
  1. Elastic Docs/
  2. Reference/
  3. Search UI/
  4. API reference/
  5. React components

Result

Displays a search result.

import { Result } from "@elastic/react-search-ui";...<SearchProvider config={config}>  {({ results }) => {    return (      <div>        {results.map(result => (          <Result key={result.id.raw}            result={result}            titleField="title"            urlField="nps_link"          />        ))}      </div>    );  }}</SearchProvider>

Certain aspects of search results can be configured inSearchProvider, using thesearchQuery configuration, such as term highlighting and search fields. See theSearch Query Configuration guide for more information.

NameDescription
className
titleFieldName of field to use as the title from each result.
shouldTrackClickThroughWhether or not to track a clickthrough event when clicked.
clickThroughTagsTags to send to analytics API when tracking clickthrough.
urlFieldName of field to use as the href from each result.
resultType:SearchResult. An object representing the search result to render.
viewUsed to override the default view for this Component. SeeView customization below.
*Any other property passed will be passed through and available to use in a Custom View

A complete guide to view customization can be found in theCustomization: Component views and HTML section.

Example:

const CustomResultView = ({  result,  onClickLink}: {  result: SearchResult,  onClickLink: () => void}) => (  <li className="sui-result">    <div className="sui-result__header">      <h3>        {/* Maintain onClickLink to correct track click throughs for analytics*/}        <a onClick={onClickLink} href={result.nps_link.raw}>          {result.title.snippet}        </a>      </h3>    </div>    <div className="sui-result__body">      {/* use 'raw' values of fields to access values without snippets */}      <div className="sui-result__image">        <img src={result.image_url.raw} alt="" />      </div>      {/* Use the 'snippet' property of fields with dangerouslySetInnerHtml to render snippets */}      <div        className="sui-result__details"        dangerouslySetInnerHTML={{ __html: result.description.snippet }}      ></div>    </div>  </li>);<Results resultView={CustomResultView} />;

The following properties are available in the view:

NameDescription
classNamePassed through from main component.
resultType:SearchResult. An object representing the search result to render.
onClickLinkfunction() - Call this when a link is clicked to trigger click tracking. Only triggered ifshouldTrackClickThrough was set to true on the main component.
titleFieldPassed through from main component. Not usually needed for custom views.
urlFieldPassed through from main component. Not usually needed for custom views.
thumbnailFieldPassed through from main component. Not usually needed for custom views.

SeeResult.tsx for an example.


[8]ページ先頭

©2009-2026 Movatter.jp