@ResponseBody @RequestMapping( value = "/autocomplete/" + COMPONENT_UID_PATH_VARIABLE_PATTERN, method = {RequestMethod.GET, RequestMethod.POST}) public AutocompleteResultData getAutocompleteSuggestions( @PathVariable final String componentUid, @RequestParam("term") final String term) throws CMSItemNotFoundException { final SearchStateData searchState = createSearchStateData(term, true); final AutocompleteResultData resultData = new AutocompleteResultData(); final SearchBoxComponentModel component = (SearchBoxComponentModel) cmsComponentService.getSimpleCMSComponent(componentUid); if (component.isDisplaySuggestions()) { resultData.setSuggestions( subList( b2bSolrProductSearchFacade.autocomplete(searchState), component.getMaxSuggestions())); } if (component.isDisplayProducts()) { final SearchPageData<ProductData> pageData = b2bSolrProductSearchFacade.search(searchState, null); resultData.setProducts(subList(pageData.getResults(), component.getMaxProducts())); } return resultData; }
protected ProductSearchPageData<SearchStateData, ProductData> performSearch( final SearchStateData searchState, final PageableData pageableData, final boolean useFlexibleSearch) { ProductSearchPageData<SearchStateData, ProductData> searchResult = createEmptySearchPageData(); if (StringUtils.isNotBlank(searchState.getQuery().getValue())) { if (useFlexibleSearch) { searchResult = (ProductSearchPageData<SearchStateData, ProductData>) flexibleSearchProductSearchFacade.search(searchState, pageableData); } else { // search using solr. searchResult = (ProductSearchPageData<SearchStateData, ProductData>) b2bSolrProductSearchFacade.search(searchState, pageableData); } } return searchResult; }
@ResponseBody @RequestMapping( value = "/autocomplete", method = {RequestMethod.GET, RequestMethod.POST}) public List<String> getAutocompleteSuggestions(@RequestParam("term") final String term) { final SearchStateData searchState = createSearchStateData(term, true); final List<String> terms = new ArrayList<String>(); for (final AutocompleteSuggestionData termData : b2bSolrProductSearchFacade.autocomplete(searchState)) { terms.add(termData.getTerm()); } return terms; }