cancel
Showing results for 
Search instead for 
Did you mean: 

How to customize auto complete in solr

Former Member
0 Kudos

Hi, I completely new to solr search. I have to implement a functionality through which the auto complete displays a combination of brand and product keyword as a single suggestion. For example- If brand is hyperice and its products associated are vyper,ice compression ,etc. Then the dropdown should be displayed hyperice-vyper,hyperice-ice compression, on typing hyper in the search box.

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Based on Version 6.0

The search box is actually a component (SearchBoxComponent) with some flags which can be configured. Flags like,

  1. displayProductImages

  2. displayProducts

  3. displaySuggestions

If you then need to have additional information like brands, then you need to tweak the following part of the code in com.zooplus.storefront.controllers.pages.SearchPageController#getAutocompleteSuggestions

                 if (component.isDisplaySuggestions())
         {            resultData.setSuggestions(subList(productSearchFacade.getAutocompleteSuggestions(term), component.getMaxSuggestions()));
         }
         if (component.isDisplayProducts())
         {            resultData.setProducts(subList(productSearchFacade.textSearch(term).getResults(), component.getMaxProducts()));
         }

Into the resultData you can add Brand facets from the result of productSearchFacade.textSearch(term). But this will give you only brands of the products in the search result.

If you want brands for a search term instead, which may or may not have products matching the term, you can do a separate search for brands and add it to the resultData.

Based on Version 5.2

I have a working code for 5.2 where we did a similar thing as is described for version 6.0

Here is an example

 final SearchBoxComponentModel component = (SearchBoxComponentModel) cmsComponentService.getSimpleCMSComponent(componentUid);
 
 if (component.isDisplaySuggestions())
 {
     resultData.setCategorySuggestions(subList(getCategorySuggestions(term), (component.getMaxProducts().intValue() + 1)));
     resultData.setKeywordSuggestions(getKeywordSuggestions(term));
     resultData.setSuggestions(subList(productSearchFacade.getAutocompleteSuggestions(term), component.getMaxSuggestions()));
     resultData.setProducts(subList(productSearchFacade.textSearch(term).getResults(), (component.getMaxProducts().intValue() + 1)));
 }

Therefore, I believe there was a SearchBoxComponent in 5.0 as well.. please check again

Former Member
0 Kudos

I didnt find any searchboxcomponent when I searched my workspace. the version which I am using is 5.0.

Former Member
0 Kudos

This is from 6.0.

I am not too sure but there would be something similar in 5.0

Former Member
0 Kudos

Can you help me with some solution in 5.0

Former Member
0 Kudos

Answer updated for 5.2

Former Member
0 Kudos

HI Shubham, I am using a much lower version, 5.0 It doesnot have SearchBoxComponentModel at all. Can you help me with it?

tylermac
Product and Topic Expert
Product and Topic Expert
0 Kudos

The search box component (https://wiki.hybris.com/display/accdoc/Search+Box+Component) was added in 5.1. You can try to backport it yourself, otherwise you will need to upgrade or build your own implementation. Be aware that as of 31.05.2016 anything <=5.1 is no longer supported by Hybris.

Former Member
0 Kudos

Abhishek,

There are two section(getAutocomplete() and getProducts in searchPagecontroller) one keyword suggestion(getAutocomplete()) means you can select from HMC>facet search config>Index type> List of index properties here there is option auto-complete just click on the check box for the field you want to consider auto suggestion. For product search(getProducts) you can configure query fields in the *your*core-spring.xml as follow

 <alias name="defaultCommerceSearchTextPopulator" alias="commerceSearchTextPopulator" />
     <bean id="defaultCommerceSearchTextPopulator"
         class="de.hybris.platform.commerceservices.search.solrfacetsearch.populators.SearchTextPopulator">
         <property name="freeTextQueryBuilders">
             <list>
                 <!-- <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder"> 
                     <property name="propertyName" value="brand" /> <property name="boost" value="100" 
                     /> </bean> -->
                 <bean
                     class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                     <property name="propertyName" value="name" />
                     <property name="boost" value="100" />
                 </bean>
             </list>
         </property>
 </bean>

Here add the field on which you want search think it helps you.

Former Member
0 Kudos

HI, Currently the dropdown displays only 5 keywords which opens up the search list page and a few keyword redirects have been applied which redirects to the brand page. What I want in the dropdown is more than 5 in the list and the order to come as following DropDown


Brands: Posture Medic®\ Posture Pro Posture Pulley Top 5 Products: Posture Pump® Cervical Disc Hydrator Model 1100 Posture Pump Elliptical Back Rocker Model 2000 etc etc etc Did You mean? Something Something 2 Something 3

Can you help?

Former Member
0 Kudos

Find the controller probably it will be Searchpagecontroller, here can find the configuer max count. If I correctly understand you, so just tick checkbox for autocomplete for Brands index properties. And for product suggestion jaust put brands and product title in the query. So just customize it in above xml.

Former Member
0 Kudos

HI Abhishek, I didnt find any configure max count option. Is it a property? Also if I add the property in spring.xml with a higher boost value so will it return the brands as a part of the autocomplete dropdown so that clicking on it will redirect me to the brand page? Brand is an itemtype inside product.

tylermac
Product and Topic Expert
Product and Topic Expert
0 Kudos

Take a look at SearchPageController.getAutocompleteSuggestions. You can see that it is calling productSearchFacade.getAutocompleteSuggestions and using the properties defined on the SearchBoxComponentModel. This page has a lot of detail on how the autocomplete functionality works.

If it's really only the result of the search coming back that isn't what you want then you should look at analyzing your solr query scoring (set log4j.logger.de.hybris.platform.solrfacetsearch.search.impl.DefaultFacetSearchService=DEBUG) to see why particular results are coming back in the order they are. You can then adjust this via:

  • Boost rules

  • Adjusting your solr scoring parameters and ensure fuzzy search is set up correctly for your "brand" attribute so it matches hyperice*

  • Adjusting your solr schema (not specific to hybris)

Former Member
0 Kudos

I wasnt able to get any solr query in the console. How can I get the autocomplete query? I am talking about autocomplete over here just the drop should contain brand names,then products and then some did you mean stuff.

Former Member
0 Kudos

What I am referring to here is not boosting a few products up. Whatever the search I did For example if I typed in ab in the search box then the suggestions that should return is, first brands containing ab,then a few products containing the name ab and then at last did you mean with a few suggesstions in the dropdown. Currently it just returns a set of keywords.

tylermac
Product and Topic Expert
Product and Topic Expert
0 Kudos

What version of hybris are you using?

Former Member
0 Kudos

I am using 5.0

Former Member
0 Kudos

This is showing different products and not a combination of brand and product which is out of the box. I need to modify out of the box autocomplete.

former_member387866
Active Contributor
0 Kudos

Hi Abhishek,

This should be working Out-Of-The-Box (OOTB). I have attached an image of this working.

Regards,
Luke