cancel
Showing results for 
Search instead for 
Did you mean: 

How to add new fq condition in Solr??

Former Member
0 Kudos

Hi there,

Could anybody explain me how I can add a new fq conditions in Solr? I want to reduce the number of products in the storefront by specific fq, but I don't now how...

It would be nice if someone could send me some useful links or feedbacks.

Thank you!

Greetz

Former Member
0 Kudos

Hi Dominik,

I have a similar requirement and am kind of stuck, were you able to find a suitable solution for adding fq condition in oslr programmatcally ?

Thanks, Subhra

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Below is the way how I have implemented:-

newSearchQuery = new String("::abc:true:xyz:false:pqr:true"); //abc , xyz , pqr are some seach parameters

With this newSearchQuery, you can call DefaultSolrProductSearchFacade.textSearch or categorySearch method.

Underlying APIs will convert newSearchQuery in correct solr query. If you check SolrSearchQueryDecoderPopulator.java, this is responsible for splitting string on :

You can then extend DefaultSolrQueryConverter to override isFilterQueryField method so that search parameter will be used either in q or fq. In the same class, you can also override convertSolrQuery method to customize query whichever way you want.

El-jaoujat
Active Participant
0 Kudos

Hi Dominic ,

Yep ! the solution i gave was related with searchText, Now the filter query that you want add con be configured on solrconfig.xml go and find the `` definition for the /select , there , you can add a specifique configuration for a list of fq parametre , the file is well documenter (comments) with some example :

 <!-- In addition to defaults, "appends" params can be specified
          to identify values which should be appended to the list of
          multi-val params from the query (or the existing "defaults").
       -->
     <!-- In this example, the param "fq=instock:true" would be appended to
          any query time fq params the user may specify, as a mechanism for
          partitioning the index, independent of any user selected filtering
          that may also be desired (perhaps as a result of faceted searching).
 
          NOTE: there is *absolutely* nothing a client can do to prevent these
          "appends" values from being used, so don't use this mechanism
          unless you are sure you always want it.
       -->
     <!--
        <lst name="appends">
          <str name="fq">inStock:true</str>
        </lst>
       -->
Former Member
0 Kudos

hi, yes this is maybe the solution which I need. But is it possible to change the value of the fq condition (in the example "true") programmatically?

My current situation looks like the following:

  • I have Solr index property whith a specifc value

  • Depending on a customer attribute, the value of the fq condition should change

Many thanks for your support!

El-jaoujat
Active Participant
0 Kudos

hi , i see ! i'm not sure if it's easily possible , but if you want to programmatically add parameters to your Solr Query the Class to look are SearchSolrQueryPopulator and maybe also SearchQuery .

Youssef,

Former Member
0 Kudos

Dominik, you could as well implement SolrQueryPostProcessor and add the changes you want in the query.

El-jaoujat
Active Participant
0 Kudos

Hi, Hybris (5.4) by default use 4 criteria to build a Solr Query ( name, ean, code, manufacturerName, keywords, and categoryName) , these are defined as a properties of the spring bean commerceSearchTextPopulator , so to add a new fq , yous should add your fq to this after redefining it on your custom extension . example :

 <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="ean"/>
                     <property name="boost" value="100"/>
                 </bean>
                 <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                     <property name="propertyName" value="code"/>
                     <property name="boost" value="90"/>
                 </bean>
                 <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                     <property name="propertyName" value="name"/>
                     <property name="boost" value="60"/>
                 </bean>
                 <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                     <property name="propertyName" value="manufacturerName"/>
                     <property name="boost" value="50"/>
                 </bean>
                 <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.ClassificationFreeTextQueryBuilder">
                     <property name="boost" value="40"/>
                 </bean>
                 <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                     <property name="propertyName" value="keywords"/>
                     <property name="boost" value="30"/>
                 </bean>
         <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                     <property name="propertyName" value="categoryName"/>
                     <property name="boost" value="10"/>
                 </bean>
                 <bean class="de.hybris.platform.commerceservices.search.solrfacetsearch.querybuilder.impl.DefaultFreeTextQueryBuilder">
                     <property name="propertyName" value="brandName"/>
                     <property name="boost" value="20"/>
                 </bean>
             </list>
         </property>
     </bean>

of course myNewFq has to be already indexed.

Former Member
0 Kudos

hi El jaoujat, thank you for your answer. But that isn't what I'm looking for. I want to filter out some products by a specific fq. For example if an user opens a category, he shouldn't see these specifics products...

your answer refers to the free text search, on which you can define different boosts for the attributes.

Does anybody else have another possible solution for my problem?