# Delivery Tier Fluent Search API

**URL:** <https://community.bloomreach.com/t/delivery-tier-fluent-search-api/3822>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [May 3, 2023, 6:40pm UTC](https://community.bloomreach.com/t/delivery-tier-fluent-search-api/3822 "2023-05-03T18:40:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andorian](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/andorian/32/1557_2.png) [@andorian](https://community.bloomreach.com/u/andorian)\
**Post date:** [May 3, 2023, 6:41pm UTC](https://community.bloomreach.com/t/delivery-tier-fluent-search-api/3822/1 "2023-05-03T18:41:00Z")

</div>

Dear Community,

Currently Im follow up this documentation

> **[Delivery Tier Fluent Search API - Bloomreach Experience Manager...](https://xmdocumentation.bloomreach.com/13/library/concepts/fluent-search/hst-fluent-search.html)**
>
> The fast and flexible on-premise or PaaS headless CMS

so I create the below classes

1. ref:  
[Define Configuration Parameters for Delivery Tier Components or REST Services - Bloomreach Experience Manager (PaaS/Self-Hosted) - The Fast and Flexible Headless CMS](https://xmdocumentation.bloomreach.com/13/library/concepts/component-development/define-component-configuration-parameters.html)

public interface SearchInfo {  
@Parameter(name = “pageSize”,  
defaultValue = “10”,  
displayName = “Page Size”)  
int getPageSize();

@Parameter(name = “documentType”,  
defaultValue = “bloomreach:basedocument”,  
displayName = “Document Type”)  
String getDocumentType();  
}

1. [Delivery Tier Fluent Search API - Bloomreach Experience Manager (PaaS/Self-Hosted) - The Fast and Flexible Headless CMS](https://xmdocumentation.bloomreach.com/13/library/concepts/fluent-search/hst-fluent-search.html)

```auto
@ParametersInfo(type = SearchInfo.class)

```

public class MySearchComponent extends BaseHstComponent {

@Override  
public void doBeforeRender(final HstRequest request, final HstResponse response)  
throws HstComponentException {  
HstRequestContext requestContext = request.getRequestContext();  
SearchInfo info = getComponentParametersInfo(request);  
// the scope to search below, for example /content/documents/myproject  
HippoBean scope = requestContext.getSiteContentBaseBean();

try {  
// parse a free text query to remove invalid chars. The argument  
// ‘false’ means no wildcards allowed  
String query = getPublicRequestParameter(request, “q”);  
String parsedQuery = SearchInputParsingUtils.parse(query, false);

```
   int pageSize = NumberUtils.toInt(getPublicRequestParameter(request, "ps"), 10);
   int pageNum = NumberUtils.toInt(getPublicRequestParameter(request, "pn"), 1);

   // 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 = HstQueryBuilder.create(scope)
            .ofTypes(BaseDocument.class)
            .where(constraint(".").contains(parsedQuery))
            .limit(pageSize)
            .offset(pageSize * (pageNum - 1))
            .orderByDescending("bloomreach:date")
            .build();

    // 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);
}

```

}

1. ftl  
[Render a Search Query Result - Bloomreach Experience Manager (PaaS/Self-Hosted) - The Fast and Flexible Headless CMS](https://xmdocumentation.bloomreach.com/13/library/concepts/search/render-a-search-query-result.html)

\<#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\> \<@hst.link var="link" hippobean=item /\> - \<@hst.cmseditlink hippobean=item/\> ${item.title?html}
 \<#if item.date?? && item.date.time??\> 

\<@fmt.formatDate value=item.date.time type="Date" pattern="MMMM d, yyyy h:mm a"/\>

${item.summary?html}

So when I run  
[localhost:9080/site/search](http://localhost:9080/site/search)

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/bloomreach1/original/2X/5/53f90571c8a9a1c7dbcc80ccf6283c4803adee64.png)

Its that expected result???

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Adam\_Pengh](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/adam_pengh/32/988_2.png) [@Adam\_Pengh](https://community.bloomreach.com/u/Adam_Pengh)\
**Post date:** [May 3, 2023, 6:47pm UTC](https://community.bloomreach.com/t/delivery-tier-fluent-search-api/3822/2 "2023-05-03T18:47:22Z")

</div>

@andorian  
The search component you’re creating expects a `q` parameter with the search term. For example, `http://localhost:8080/site/search?q=search-term`

The two lines below that you have in the component take the query parameter and parse it:

```auto
String query = getPublicRequestParameter(request, “q”);
String parsedQuery = SearchInputParsingUtils.parse(query, false);

```

Then the `hstQuery` uses the `parsedQuery` in the `where` contstraint

---

<div class="post-metadata">

**Author:** ![andorian](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/andorian/32/1557_2.png) [@andorian](https://community.bloomreach.com/u/andorian)\
**Post date:** [May 9, 2023, 8:06pm UTC](https://community.bloomreach.com/t/delivery-tier-fluent-search-api/3822/3 "2023-05-09T20:06:52Z")

</div>

Hi Adam,

Thank you for your answer

Should I add a form to display the response?

When i send the request  
[http://localhost:8080/site/search?q=search-term](http://localhost:8080/site/search?q=search-term)  
I see the same message " Please fill in a search term"

Is there an example.how to test this??

---

<div class="post-metadata">

**Author:** ![Adam\_Pengh](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/adam_pengh/32/988_2.png) [@Adam\_Pengh](https://community.bloomreach.com/u/Adam_Pengh)\
**Post date:** [May 17, 2023, 5:42pm UTC](https://community.bloomreach.com/t/delivery-tier-fluent-search-api/3822/4 "2023-05-17T17:42:37Z")

</div>

@andorian  
Hello,

Below is a link to the Essentials Search Component freemarker templates. There are 2 templates:

1. A search box to submit a search term to the search page
2. The search results page to render the search results

> **[brxm/essentials/plugins/search/src/main/resources/instructions/freemarker at...](https://github.com/bloomreach/brxm/tree/brxm-15.2.2/essentials/plugins/search/src/main/resources/instructions/freemarker)**
>
> brxm-15.2.2/essentials/plugins/search/src/main/resources/instructions/freemarker

---

<div class="post-metadata">

**Author:** ![andorian](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/andorian/32/1557_2.png) [@andorian](https://community.bloomreach.com/u/andorian)\
**Post date:** [May 17, 2023, 6:33pm UTC](https://community.bloomreach.com/t/delivery-tier-fluent-search-api/3822/5 "2023-05-17T18:33:01Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![Tarun\_Sujanani](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/tarun_sujanani/32/1514_2.png) [@Tarun\_Sujanani](https://community.bloomreach.com/u/Tarun_Sujanani)\
**Post date:** [July 12, 2023, 10:59am UTC](https://community.bloomreach.com/t/delivery-tier-fluent-search-api/3822/6 "2023-07-12T10:59:13Z")

</div>

Hello @andorian,  
We are happy you are part of Bloomreach Developer’s Community.  
Thank you for reaching out to us.  
We hope we have answered your queries and therefore marking this thread for Closure.

Looking forward to your continuous contribution towards our vibrant Bloomreach Community.

Thank you
