2019 Sep 06 12:30 PM - edited 2024 Feb 04 6:49 AM
Please let me know how to enable auto suggestions at PLP page. Let us say if I search with characters in the search box at PLP I need to list of suggested products with that characters. Let me know how to implement this. Thanks in advance.
Request clarification before answering.
Hi Yeshwanth Kumar Thotam Setty,
to implement autosuggestion from the scratch you have to:
$solrIndexedType = productType
INSERT_UPDATE SolrIndexedProperty; solrIndexedType(identifier)[unique = true]; name[unique = true]; useForAutocomplete[default = false]
; $solrIndexedType ; code ; true
; $solrIndexedType ; name ; true
@ResponseBody
@RequestMapping(value = "/autocomplete", method = RequestMethod.GET)
public List<String> getAutocompleteSuggestions(@RequestParam("term") final String term)
{
final String termSanitized = SecurityUtil.sanitize(term);
final List<String> terms = new ArrayList<String>();
for (final AutocompleteSuggestionData termData : solrProductSearchFacade.getAutocompleteSuggestions(termSanitized))
{
terms.add(termData.getTerm());
}
return terms;
}@ResponseBody
@RequestMapping(value = "/autocomplete/" + COMPONENT_UID_PATH_VARIABLE_PATTERN, method = RequestMethod.GET)
public AutocompleteResultData getAutocompleteSuggestions(@PathVariable final String componentUid,
@RequestParam("term") final String term) throws CMSItemNotFoundException
{
final String termSanitized = SecurityUtil.sanitize(term);
final AutocompleteResultData resultData = new AutocompleteResultData();
resultData.setSuggestions(subList(solrProductSearchFacade.getAutocompleteSuggestions(termSanitized), MAX_PRODUCTS_ELEMENTS));
resultData.setProducts(subList(solrProductSearchFacade.textSearch(termSanitized).getResults(), MAX_PRODUCTS_ELEMENTS));
return resultData;
}Hope this helps,
Igor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.