CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
4,168

Purpose


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.

Overview


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>
</div>

My second method


Only need modify jsp page. the function is same.

  • Page myCouponsListPage.jsp


<c:choose>
<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>
</c:when>
<c:otherwise>
<a class="btn btn-primary btn-block" href="c/${coupon.rootCategory}?q=%3Arelevance%3AchineseCouponCode%3A${coupon.promotionCode}&text=#"><spring:theme code="coupon.FindProducts"/></a>
</c:otherwise>
</c:choose>

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="de.hybris.platform.commerceservices.search.facetdata.ProductCategorySearchPageData" />
<property name="populators">
<list>
<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" />
</list>
</property>
</bean>