Solr MoreLikeThis in Hybris

22 Views Asked by At

I'm trying to get results from solr 'MoreLikeThis' search in Hybris. For example: If I try to query solr in Solr UI , query will look like this -

https://localhost:8983/solr/master_backoffice_backoffice_product_flip/mlt?indent=true&mlt.count=10&mlt.fl=manufacturerName_text%2Cdescription_text_en%2CcatalogVersion%2Ccategory_string_mv&mlt.match.include=true%2Ctrue&q.op=AND&q=id%3A8796102066177%2CcatalogVersion%3AOnline

And in the result I will take smth like this :

    {
  "responseHeader":{
    "status":0,
    "QTime":3},
  "match":{"numFound":1,"start":0,"numFoundExact":true,"docs":[
      {
       
  },
  "response":{"numFound":433,"start":0,"numFoundExact":true,"docs":[
      {
   

The response will include a section match, which includes the original document. The response section includes the similar documents.

Before that I added Request Handler in solrconfig.xml -

<requestHandler name="/mlt" class="solr.MoreLikeThisHandler">
        <str name="mlt.fl">body</str>
</requestHandler>

How can I perform this request in Hybris and get the ProductData results ? As far as I know Hybris does not have OOTB implementation for Solr MoreLikeThis. Maybe someone has some workarounds or advices regarding this?

Also , I found another way how to get 'MoreLikeThis' results directly in Hybris.By overriding OOTB DefaultFacetSearchService and adding those query params :

 public SearchQuery createFreeTextSearchQueryFromTemplate (FacetSearchConfig facetSearchConfig, IndexedType indexedType, String queryTemplateName, String userQuery) {
        final SearchQuery searchQuery = super.createFreeTextSearchQueryFromTemplate(facetSearchConfig, indexedType, queryTemplateName, userQuery);
        searchQuery.addRawParam("mlt", "true");
        searchQuery.addRawParam("mlt.fl", "fulltext_en,catalogVersion,category_string_mv");
        searchQuery.addRawParam("mlt.count", "10"); //count of documents in the response
        searchQuery.addRawParam("mlt.mindf", "2"); //min document frequency
        searchQuery.addRawParam("mlt.mintf", "1"); //min term frequency
        return searchQuery;
    }

In a result we can access the 'MoreLikeThisResult' in following way -

SolrSearchResult.getSolrObject().getResponse().get(“moreLikeThis”))

But In the result, we will have different data structure from simple Solr search result , and we cant reuse the existing implementation of fetching, converting, populating and so on... So , maybe there is more easy way to fetch 'MoreLikeThis' result from solr, in order not to implement the whole flow.

0

There are 0 best solutions below