Delivery Tier Search API - BloomReach Experience - Open Source CMS

This article covers a Hippo CMS version 10. There's an updated version available that covers our most recent release.


Delivery Tier Search API



Create and execute search queries and render the results.


Hippo's delivery tier (HST) provides a Java API to create and execute searches. When an HST query is executed, the HstQuery object is translated into a JCR XPath query, which is executed in the Hippo Repository. The Hippo Repository returns JCR Nodes as hits, that in turn are mapped to HippoBeans in the HstQueryResult object.


Below, there are examples for a Java HstComponent snippet, JSP and Freemarker snippets and a schematic (not exact!) drawing of how all involved components interact. In the child pages, we explain all steps in more detail.

MySearchComponent Java Code Snippet

Java Class MySearchComponent:

public class MySearchComponent extends BaseHstComponent {

    public void doBeforeRender(final HstRequest request,
                               final HstResponse response)
                                      throws HstComponentException {

        HstRequestContext context = request.getRequestContext();
        SearchInfo info = getComponentParametersInfo(request);
        // the scope to search below, for example /content/documents/example
        HippoBean scope = getSiteContentBaseBean(request);
        try {
            // create the query to search below 'scope', return beans that are
            // of type BaseDocument bean or a subclass/sub-jcr-types, the
            // third argument, 'true', indicates whether to include subtypes
            HstQuery hstQuery =
                                                     BaseDocument.class, true);
            // always set a limit! The limit is normally the pageSize,
            // for example 10
            // the offset : Assume requested page is 3. Then the offset is 20
            hstQuery.setOffset(pageSize * (currentPage - 1));
            // we assume ordering on property "mynamespace:date" descending

            // parse a free text query to remove invalid chars. The argument
            // 'false' means no wildcards allowed
            String parsedQuery = SearchInputParsingUtils.parse(query, false);

            if (StringUtils.isNotEmpty(parsedQuery)) {
                // create a filter
                Filter f = hstQuery.createFilter();
                // add a constraint: Only Documents that contain the terms
                // in parsedQuery will be a hit
                // Note that "." means: Search in the entire Document
                // including all descendant jcr nodes
                f.addContains(".", parsedQuery);
                // apply the filter

            // execute the query
            HstQueryResult result = hstQuery.execute();

            // set the result, info and parsedQuery on the HstRequest : It is
            // then available in the JSP
            request.setAttribute("result", result);
            request.setAttribute("info", info);
            request.setAttribute("query", parsedQuery);

        } catch (QueryException e) {
            throw new HstComponentException(
             "Exception occured during creation or execution of HstQuery.", e);


Template Code Snippets to Iterate through HippoBeans in the Result

JSP Snippet example using HstQueryResult:

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

Freemarker snippet:

<#include "/WEB-INF/freemarker/include/imports.ftl">
  ${info.title?html} for '${query?html}': ${result.totalSize} results
  <#-- Iterate through the hippoBeans on the result -->
  <#if result?? && result.hippoBeans?has_content>
    <#list result.hippoBeans as item>
      < var="link" hippobean=item />
      <li class="overview-item">
        <@hst.cmseditlink hippobean=item/>
        <a href="${link}">${item.title?html}</a>
          <#if &&>
            <p><@fmt.formatDate type="Date" pattern="MMMM d, yyyy h:mm a"/></p>

Global Overview of Involved Components


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?