<miso-products>

The search results. Hybrid Search shows them under the answer, and loads more as the reader scrolls:

<miso-hybrid-search>
  <miso-query></miso-query>
  <miso-answer></miso-answer>
  <miso-products></miso-products>
</miso-hybrid-search>

Containers

ContainerDefault layoutFields from
<miso-hybrid-search>list: one result on each rowfl on client.ui.hybridSearch

To change the results, call useLayouts on client.ui.hybridSearch, under the role products.

Layouts

Give the layout type before the options:

client.ui.hybridSearch.useLayouts({
  products: ["cards", { link: { open: false } }],
});
TypeWhat the reader seesClass
listOne result on each row.miso-list
cardsResults side by side, in a grid.miso-cards

carousel and horizontal also draw the results, but they do not load more as the reader scrolls. Use them only when the first page of results is enough.

Options

Your options are merged over the defaults, so set only what you change.

OptionWhat it does
linkWhere the links open. { open: false } opens them in the same tab. Also takes target and rel.
classNameThe class of the layout, in place of the one in the table above.
templates.productThe markup of one result.

Write the markup of a result

Give your own function as the product template. It returns the HTML of one result. This one shows the image, the title and the description:

function renderProduct(layout, state, data, meta) {
  const { tagPair, escapeHtml } = layout.templates.helpers;
  const [openTag, closeTag] = tagPair(layout, data);
  const image = data.cover_image
    ? `<img class="my-result-image" src="${escapeHtml(data.cover_image)}" alt="">`
    : "";
  return openTag +
    image +
    `<div class="my-result-title">${escapeHtml(data.title)}</div>` +
    `<div class="my-result-description">${escapeHtml(data.description || "")}</div>` +
    closeTag;
}

client.ui.hybridSearch.useLayouts({
  products: { templates: { product: renderProduct } },
});
ArgumentWhat it holds
layoutThe layout. layout.templates.helpers has tagPair and escapeHtml.
stateThe state of the whole list.
dataThe result. It holds only the fields that fl asks for, with product_id and title always there.
metameta.index is the position of the result, counted from 0.
  • Start with tagPair. It returns the opening and closing tag of the item, which link to the article and record clicks on it.
  • Ask for the fields you show. description is not in the default fl. Add it with useApi, as Write the markup of a result shows.
  • Escape every value from the record with escapeHtml.
  • Style your own classes in your CSS.

Next