}
@RequestMapping(value = FoUrls.CATALOG_SEARCH_URL, method = RequestMethod.GET)
public ModelAndView search(final HttpServletRequest request, final Model model, @Valid SearchForm searchForm) throws Exception {
ModelAndViewThemeDevice modelAndView = new ModelAndViewThemeDevice(getCurrentVelocityPath(request), FoUrls.CATALOG_SEARCH.getVelocityPage());
final RequestData requestData = requestUtil.getRequestData(request);
if (StringUtils.isEmpty(searchForm.getText())
&& searchForm.getPage() == 0) {
return displaySearch(request, model);
}
String url = requestUtil.getCurrentRequestUrl(request);
String sessionKeyPagedListHolder = "Search_ProductMarketing_PagedListHolder_" + request.getSession().getId();
String sessionKeyFacet = "Search_ProductMarketing_Facet_" + request.getSession().getId();
int page = searchForm.getPage() - 1;
String mode = request.getParameter(Constants.PAGE_VIEW_MODE);
String sortBy = searchForm.getSortBy();
String order = searchForm.getOrder();
try {
PagedListHolder<SearchProductItemViewBean> productsViewBeanPagedListHolder;
if(searchForm.getPage() == 0){
ProductMarketingResponseBean productMarketingResponseBean = null;
if(searchForm.getPrice() != null){
productMarketingResponseBean = productMarketingSolrService.searchProductMarketing(ProductMarketingResponseBean.PRODUCT_MARKETING_DEFAULT_SEARCH_FIELD,
searchForm.getText(), ProductMarketingResponseBean.PRODUCT_MARKETING_DEFAULT_FACET_FIELD, searchForm.getPrice().getStartValue(), searchForm.getPrice().getEndValue(),
searchForm.getCatalogCategoryList());
productMarketingResponseBean = productMarketingSolrService.searchProductMarketing(ProductMarketingResponseBean.PRODUCT_MARKETING_DEFAULT_SEARCH_FIELD,
searchForm.getText(), ProductMarketingResponseBean.PRODUCT_MARKETING_DEFAULT_FACET_FIELD, searchForm.getPrice().getStartValue(), searchForm.getPrice().getEndValue());
} else {
productMarketingResponseBean = productMarketingSolrService.searchProductMarketing(ProductMarketingResponseBean.PRODUCT_MARKETING_DEFAULT_SEARCH_FIELD,
searchForm.getText(), ProductMarketingResponseBean.PRODUCT_MARKETING_DEFAULT_FACET_FIELD);
}
productsViewBeanPagedListHolder = initList(request, sessionKeyPagedListHolder, productMarketingResponseBean, new PagedListHolder<SearchProductItemViewBean>(), searchForm);
// FACETS
List<SearchFacetViewBean> facets = frontofficeViewBeanFactory.buildListViewBeanCatalogSearchFacet(requestData, productMarketingResponseBean);
modelAndView.addObject(AbstractSolrService.SEARCH_FACET_FIELD_LIST, facets);
request.getSession().setAttribute(sessionKeyFacet, facets);
} else {
productsViewBeanPagedListHolder = (PagedListHolder<SearchProductItemViewBean>) request.getSession().getAttribute(sessionKeyPagedListHolder);
// FACETS
List<SearchFacetViewBean> facets = (List<SearchFacetViewBean>) request.getSession().getAttribute(sessionKeyFacet);
modelAndView.addObject(AbstractSolrService.SEARCH_FACET_FIELD_LIST, facets);
}
int pageCurrent = productsViewBeanPagedListHolder.getPage();
if (pageCurrent < page) {
for (int i = pageCurrent; i < page; i++) {
productsViewBeanPagedListHolder.nextPage();
}
} else if (pageCurrent > page) {
for (int i = page; i < pageCurrent; i++) {
productsViewBeanPagedListHolder.previousPage();
}
}
modelAndView.addObject(Constants.PAGINATION_PAGE_URL, url);
modelAndView.addObject(Constants.PAGINATION_PAGE_PAGED_LIST_HOLDER, productsViewBeanPagedListHolder);
modelAndView.addObject(Constants.SEARCH_TEXT, searchForm.getText());
modelAndView.addObject(Constants.PAGINATION_PAGE_SIZE, productsViewBeanPagedListHolder.getPageSize());
modelAndView.addObject(Constants.PAGINATION_SORT_BY, sortBy);
modelAndView.addObject(Constants.PAGINATION_ORDER, order);
modelAndView.addObject(Constants.PRICE_RANGE_PARAMETER, searchForm.getPrice());
modelAndView.addObject(Constants.CATALOG_CATEGORIES_PARAMETER, searchForm.getCategoriesFilter());
} catch (Exception e) {
logger.error("SOLR Error", e);
return displaySearch(request, model);
}
loadRecentProducts(request, requestData, model, new FetchPlan(categoryVirtualFetchPlans), new FetchPlan(productMarketingFetchPlans), new FetchPlan(productSkuFetchPlans));
final Cart currentCart = requestData.getCart();
final CartViewBean cartViewBean = frontofficeViewBeanFactory.buildViewBeanCart(requestUtil.getRequestData(request), currentCart);
modelAndView.addObject(ModelConstants.CART_VIEW_BEAN, cartViewBean);
overrideDefaultSeoPageTitleAndMainContentTitle(request, modelAndView, FoUrls.CATALOG_SEARCH.getKey());
return modelAndView;
}