This article covers a Bloomreach Experience Manager version 11. There's an updated version available that covers our most recent release.

Render a Search Query Result

Introduction

Goal

Render the results of a search query in Hippo's delivery tier.

Background

Hippo's delivery tier provides Search APIs to query the content repository from within a delivery tier component. This page provides examples of JSP and Freemarker templates to render the result set of a query constructed and executed using either the Fluent Search API or the Legacy Search API.

Example

The example templates below render the result of a query constructed and executed as shown in the example component classes on the following two pages:

The two APIs are functionally equivalent and both result in the same HstQueryResult object. Hence, the same template can be used in combination with the examples of both APIs.

JSP

<%@ include file="/WEB-INF/jspf/htmlTags.jspf" %>
<h2>
  <c:out value="${requestScope.info.title}"/> for '<c:out value="${requestScope.query}"/>' :
                                             ${requestScope.result.totalSize} results
</h2>
<ul>
  <%-- Iterate through the hippoBeans on the result --%>
  <c:forEach var="item" items="${requestScope.result.hippoBeans}">
    <hst:link var="link" hippobean="${item}"/>
    <li>
      <hst:cmseditlink hippobean="${item}"/>
      <a href="${link}">${item.title}</a>
      <div>
        <c:if test="${hst:isReadable(item, 'date.time')}">
          <p><fmt:formatDate value="${item.date.time}"
                             type="Date" pattern="MMMM d, yyyy h:mm a"/></p>
        </c:if>
        <p>${item.summary}</p>
      </div>
    </li>
  </c:forEach>
</ul>

Freemarker

<#include "/WEB-INF/freemarker/include/imports.ftl">
<h2>
  ${info.title?html} for '${query?html}': ${result.totalSize} results
</h2>
<ul>
  <#-- Iterate through the hippoBeans on the result -->
  <#if result?? && result.hippoBeans?has_content>
    <#list result.hippoBeans as item>
      <@hst.link var="link" hippobean=item />
      <li>
        <@hst.cmseditlink hippobean=item/>
        <a href="${link}">${item.title?html}</a>
        <div>
          <#if item.date?? && item.date.time??>
            <p><@fmt.formatDate value=item.date.time type="Date" pattern="MMMM d, yyyy h:mm a"/></p>
          </#if>
          <p>${item.summary?html}</p>
        </div>
      </li>
    </#list>
  </#if>
</ul>
Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?