2020-09-14 18:46发布
加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)
专家们,
我需要如下自定义自动建议:-
搜索框组件中的搜索词应与产品名称/说明匹配,并且匹配产品的所有相关类别均应显示为自动提示。
开箱即用的Hybris将搜索词与类别名称匹配。
谢谢,SPS。
@ResponseBody @RequestMapping(value ="/img/autocomplete",方法= RequestMethod.GET) 公共AutocompleteResultData getAutocompleteSuggestions(@RequestParam(" term")最终String术语) { 最终List 项=新的ArrayList (); 布尔值addFacet = true; 最终的AutocompleteResultData resultData = new AutocompleteResultData(); 最终List autocompleteSuggestionData = productSearchFacade.getAutocompleteSuggestions(term); 用于(最终AutocompleteSuggestionData termData:autocompleteSuggestionData) { terms.add(termData.getTerm()); 如果(addFacet) { addFacet = false; 最终FacetSearchPageData searchPageData = commerceProductSearchService .textSearch(term,null); 最终List >构面= searchPageData.getFacets(); 用于(最终FacetData facetData:facets) { 如果(CATEGORY_FACET_NAME.equalsIgnoreCase(facetData.getName())) { resultData.setCategoryResults(getCategories(facetData,term)); } } resultData.setProductCount(searchPageData.getPagination()。getTotalNumberOfResults()); } } 最终List 产品= productSearchFacade.textSearch(term).getResults(); 如果(CollectionUtils.isNotEmpty(products)) { resultData.setProducts(sublist(products)); } resultData.setSuggestions(terms); resultData.setOriginalTerm(term); 返回resultData; } 私有List getCategories(最终FacetData facetData,最后的String项) { 最终的List 类别=新的ArrayList <>(); 用于(最终FacetValueData facetValueData:facetData.getTopValues()) { 最终的CategoryData数据= new CategoryData(); data.setCode(facetValueData.getCode()); data.setName(facetValueData.getName()); //这很丑陋,但我们必须以这样一种方式来生成查询URL,即它是所选文本和所单击类别之间的AND。 //%3A是`:`的URL编码值 最终字符串categoryUrl = Config.getParameter(" website.url.https")+"/img/search?q =" +条款 +"%3Arelevance%3Acategories%3A" + facetValueData.getCode(); data.setUrl(categoryUrl); 最终的CategoryResultData categoryResultData =新的CategoryResultData(); categoryResultData.setCategory(data); categoryResultData.setCount(facetValueData.getCount()); Categories.add(categoryResultData); } 返回类别; }
web \ webroot \ WEB-INF_ui-src\ response \ lib \ ybase-0.1.0 \ js \ acc.autocomplete.js
if(data.categories!= null){$ .each(data.categories,function(i,obj){autoSearchData.push({value:ACC.sanitizer.sanitize(obj.name),url:ACC。 config.encodedContextPath +"/img/search?q =" + encodeURIComponent(data.searchTerm)+"%3Arelevance%3Abrand%3A" +"&category_string =" + encodeURIComponent(obj.code),搜索词:ACC.sanitizer.sanitize(data。 searchTerm),键入:" categoryResult"});}); }
最多设置5个标签!
web \ webroot \ WEB-INF_ui-src\ response \ lib \ ybase-0.1.0 \ js \ acc.autocomplete.js
if(data.categories!= null){$ .each(data.categories,function(i,obj){autoSearchData.push({value:ACC.sanitizer.sanitize(obj.name),url:ACC。 config.encodedContextPath +"/img/search?q =" + encodeURIComponent(data.searchTerm)+"%3Arelevance%3Abrand%3A" +"&category_string =" + encodeURIComponent(obj.code),搜索词:ACC.sanitizer.sanitize(data。 searchTerm),键入:" categoryResult"});}); }
一周热门 更多>