on ‎2018 Aug 09 7:38 PM
Hi Experts,
I need to customize the autosuggestion as follows:-
The search term in search box component should be matched in product name/description and all relevant categories of matching products should be shown as autosuggestion.
The out of the box Hybris matches the search term with category name.
Thanks, SPS.
Request clarification before answering.
@ResponseBody
@RequestMapping(value = "/autocomplete", method = RequestMethod.GET)
public AutocompleteResultData getAutocompleteSuggestions(@RequestParam("term") final String term)
{
final List<String> terms = new ArrayList<String>();
boolean addFacet = true;
final AutocompleteResultData resultData = new AutocompleteResultData();
final List<AutocompleteSuggestionData> autocompleteSuggestionData = productSearchFacade.getAutocompleteSuggestions(term);
for (final AutocompleteSuggestionData termData : autocompleteSuggestionData)
{
terms.add(termData.getTerm());
if (addFacet)
{
addFacet = false;
final FacetSearchPageData<SolrSearchQueryData, SearchResultValueData> searchPageData = commerceProductSearchService
.textSearch(term, null);
final List<FacetData<SolrSearchQueryData>> facets = searchPageData.getFacets();
for (final FacetData<SolrSearchQueryData> facetData : facets)
{
if (CATEGORY_FACET_NAME.equalsIgnoreCase(facetData.getName()))
{
resultData.setCategoryResults(getCategories(facetData, term));
}
}
resultData.setProductCount(searchPageData.getPagination().getTotalNumberOfResults());
}
}
final List<ProductData> products = productSearchFacade.textSearch(term).getResults();
if (CollectionUtils.isNotEmpty(products))
{
resultData.setProducts(sublist(products));
}
resultData.setSuggestions(terms);
resultData.setOriginalTerm(term);
return resultData;
}
private List<CategoryResultData> getCategories(final FacetData<SolrSearchQueryData> facetData, final String term)
{
final List<CategoryResultData> categories = new ArrayList<>();
for (final FacetValueData<SolrSearchQueryData> facetValueData : facetData.getTopValues())
{
final CategoryData data = new CategoryData();
data.setCode(facetValueData.getCode());
data.setName(facetValueData.getName());
// this is ugly but we have to make query URL in such a way that it is an AND between the selected text and the category which is clicked.
// %3A is URL encoded value for `:`
final String categoryUrl = Config.getParameter("website.url.https") + "/search?q=" + term
+ "%3Arelevance%3Acategories%3A" + facetValueData.getCode();
data.setUrl(categoryUrl);
final CategoryResultData categoryResultData = new CategoryResultData();
categoryResultData.setCategory(data);
categoryResultData.setCount(facetValueData.getCount());
categories.add(categoryResultData);
}
return categories;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
web\webroot\WEB-INF_ui-src\responsive\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 + "/search?q=" + encodeURIComponent(data.searchTerm)+"%3Arelevance%3Abrand%3A"+"&category_string="+encodeURIComponent(obj.code), searchterm: ACC.sanitizer.sanitize(data.searchTerm), type: "categoryResult" }); }); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Saurabh , I see that in DefaultSolrProductSearchFacade.java we have the method textSearch this method returns ProductSearchPageData.
I am not sure where should I customize to get the categories for a product. Any pointers will help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fuzzy search is very expensive operation. See an excellent answer below https://stackoverflow.com/questions/10880976/solr-lucene-fuzzy-search-too-slow
won't be a good user experience.
changing algorithms on /suggest would not make any difference as solr suggestions use /spellcheck endpoint. So if you wish to tweak Tokenizers, do it on /spellcheck.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @sps : Please follow the link where I explained how solr works. If you wish solr text search to only look at product name/description. Then make these 2 fields as text and rest of the fields as string or double.
So, solr will only make tokens out of product name/description. When you search, you will get results based on your search input matching product name/description.
When you get search results, exact all categories from the result set and display to the user. See a working example here: https://www.bestandless.com.au/
Go to the above URL and search women or dresses
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Even I was looking for same !! So, please find some details which i think can be useful.
In the SearchPageController there is a method called getAutocompleteSuggestions.
After debugging the same you will reach to DefaultSolrAutoSuggestService.getAutoSuggestionsForQuery method which internally forms the Solr Query and use SolrJ to make a webservice call to Solr Server. Which Returns the information.
In the SolrConfig.xml go to the requestHandler /suggest change the alogoithm on respective searchComponent to FuzzyLookUp. Additionally u might need to change tokenizer to KeywordTokenizer on autosuggest in schema.xml
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.