As we all know SAP Hybris works with Apache SOLR to provide enhanced product search
capabilities and there are some features that are supported by the SOLR but not supported
So, this article will tell about
- SOLR NOT query in Hybris
- Multi-Line Exact Search with provided order
- SOLR Query with POST method in Hybris
SOLR NOT query in Hybris
Suppose we have scenario where we don’t want to show specific product for specific
condition on listing page/search page
we don’t want to show product whose color is black or we don’t want to show
specific product to specific customer.
In SOLR you can simply achieve this by specifying NOT or ~ in a FQ (Filtered Query) like
FQ = ~color : BLACK
FQ = NOT color : BLACK
But if you want to achieve same in Hybris you need to add this is in the filter query
and at the end SolrQueryConverter will convert SearchQuery to SolrQuery and this will send
to the SOLR to retrieve Product from SOLR.
But the problem is when you append “Not” OR “~” in the Filtered Query the
SolrQueryConverter will covert “~ to \~” and “NOT to NOT\+” because it escape query
character’s from query and hence you will not get result because query which will be passed
like “FQ = \~color : BLACK” or “FQ = NOT\+color : BLACK” so to overcome with this problem
you need to override SolrQueryConverter and don’t escape query character form Filter
Query Field on which you want apply not condition.
Multi-Line Exact Search with provided order
User can provide multiple product code and SOLR should return result in a same
order provided by user.
As we know it was easily achievable by implementing own
CommerceSearchTextPopulator but the only tricky part is that the result should come in
same order as provided by the user.
Because each product (document in term of SOLR) having its score and this is
defined at the indexing time and because of this scoring factor you will not get result in a
same order as provided by user.
To overcome with this problem dynamic scoring is applied while sending query to
the SOLR. And to support more than 500+ product search in a single SOLR query we used
POST Method for sending query. Below I have explained how to use SOLR query with POST
method in Hybris
SOLR query with POST method in Hybris
OOTB the box Hybris uses GET method to send query to SOLR Server However, SOLR
also supports POST requests for select queries. If you use complex SOLR queries with lots of
facets and/or Filter Queries where the total length of your query string can exceed the limits
of servlet containers then SOLR will throw error and you will not get expected result.
And hence we can use post method to send query to the SOLR server and to achieve
this in Hybris we need to override FacetSearchStrategy and pass method as a POST with