Dear Community,
Currently Im follow up this documentation
so I create the below classes
public interface SearchInfo {
@Parameter(name = “pageSize”,
defaultValue = “10”,
displayName = “Page Size”)
int getPageSize();
@Parameter(name = “documentType”,
defaultValue = “bloomreach:basedocument”,
displayName = “Document Type”)
String getDocumentType();
}
@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);
}
}
<#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
Its that expected result???
Thanks in advance