Skip to Content
Author's profile photo Former Member

The skills of hybris solr facets search development


When I develop a new feature need use facets as a query condition to search in solr engine.The first development took two days to develop and there were some problems, the second time I found another way to spend only half a day and no problem. It means I waste 1.5 days. So I put it here.


The feature is that we hope quickly find out products meet coupon conditions, meanwhile we should reuse the products list page and keeping the funcation in pdp page is work well. This case contain two parts to do.

  • The first step is add new field chinesecoupon to product index in solr engines.
  • The second step in hybris storefront to get result in solr engines.

My problem occurred in the second step, I add a new controller to handle the request, but ProductSearchService has provided this method. we understand the use of this is method not enough depth. This article compares the two implementations of the second step and depth analysis of the solr query structure in storefront layer.

My first method

I create a controller and a facade to handle the request by myself. Then I use the controller for page to request.

  • Class

  • Active

  • Page myCouponsListPage.jsp
<div class="col-md-6">
<a class="btn btn-primary btn-block" href="coupon/findproducts/${coupon.promotionCode}"><spring:theme code="coupon.FindProducts"/></a>

My second method

Only need modify jsp page. the function is same.

  • Page myCouponsListPage.jsp
<c:when test="${coupon.ifShowAllProduct}">
<a class="btn btn-primary btn-block" href="c/${coupon.rootCategory}?q=%3Arelevance&text=#"><spring:theme code="coupon.FindProducts"/></a>
<a class="btn btn-primary btn-block" href="c/${coupon.rootCategory}?q=%3Arelevance%3AchineseCouponCode%3A${coupon.promotionCode}&text=#"><spring:theme code="coupon.FindProducts"/></a>

This method use SearchPageController provide funcational it can support search use facet condition.

Solr search analysis

  • Key Class

  • key method every search will in this process.
// Create the SearchQueryPageableData that contains our parameters
final SearchQueryPageableData<SolrSearchQueryData> searchQueryPageableData = buildSearchQueryPageableData(searchQueryData, pageableData);

// Build up the search request
final SolrSearchRequest solrSearchRequest = getSearchQueryPageableConverter().convert(searchQueryPageableData);

// Execute the search
final SolrSearchResponse solrSearchResponse = getSearchRequestConverter().convert(solrSearchRequest);

// Convert the response
return getSearchResponseConverter().convert(solrSearchResponse);
  • Populator every search will will the fellow populator to poplate in search. My second method is use SearchResponseFacetsPopulator to handle the request so I should not use my controller.
<alias name="defaultCommerceSolrSearchResponseConverter" alias="commerceSolrSearchResponseConverter" />
<bean id="defaultCommerceSolrSearchResponseConverter" parent="abstractPopulatingConverter">
<property name="targetClass" value="" />
<property name="populators">
		<ref bean="commerceSearchResponseQueryPopulator" />
		<ref bean="commerceSearchResponsePaginationPopulator" />
		<ref bean="commerceSearchResponseResultsPopulator" />
		<ref bean="commerceSearchResponseFacetsPopulator" />
		<ref bean="commerceSearchResponseFacetFilterPopulator" />
		<ref bean="commerceSearchResponseBreadcrumbsPopulator" />
		<ref bean="commerceSearchResponseSortsPopulator" />
		<ref bean="commerceSearchResponseFreeTextSearchPopulator" />
		<ref bean="commerceSearchResponseCategoryCodePopulator" />
		<ref bean="commerceSearchResponseSubCategoriesPopulator" />
		<ref bean="commerceSearchResponseSpellingSuggestionPopulator" />
		<ref bean="commerceSearchResponseKeywordRedirectPopulator" />

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.