2

I have a Solr indexed property called isNewProduct (boolean) and I want to create a new Solr By option for this attribute. (the products with isNewProduct==true must appear first).

Any hint about how can I achieve this ?

HybrisHelp
  • 5,518
  • 2
  • 27
  • 65
Nexussim Lements
  • 535
  • 1
  • 15
  • 47
  • Have you seen [Hybris Solr Sort](https://stackoverflow.com/questions/49512571/hybris-solr-sort)? You should be able to follow the same plan for `isNewProduct`. – MatsLindh Aug 13 '19 at 14:38
  • I've followed this https://www.helphybris.com/2018/03/how-to-add-custom-sort-by-option-in-hybris.html and It didn't worked – Nexussim Lements Aug 13 '19 at 14:52
  • The link you tried to follow is for custom comparator but here in your case you do not need to write any custom comparator. @MatsLindh pointed correct link. For boolean or string value, you can do it without changing any code. Follow [how to add or update Sort by Options](https://www.helphybris.com/2018/03/how-to-update-short-by-option-hybris.html) – HybrisHelp Aug 14 '19 at 07:28

1 Answers1

2

All you have to do is run below Impex (change it with your actual values) and you are done.

    $lang=en
    $solrIndexedType=YourProductType


    INSERT_UPDATE SolrSort ; indexedType(identifier)[unique=true] ; code[unique=true] ; name[lang=$lang] ; useBoost
                           ; $solrIndexedType                     ; isNewProduct      ; New Product      ;false 

    INSERT_UPDATE SolrSortField ; sort(indexedType(identifier),code)[unique=true] ; fieldName[unique=true] ; ascending[unique=true]
                                ; $solrIndexedType:isNewProduct                   ; isNewProduct           ; true 

Please note, when we add a new SolrSort, Hybris internally added its reference to SolrIndexedType in sorts field so that you can see that option on the storefront. But if your SolrSort value is missing, you can always verify and correct it using back-office/Impex.

Something like below

INSERT_UPDATE SolrIndexedType ; identifier[unique=true] ; sorts(code)                                    
                              ; $solrIndexedType        ; SolrSortCode1,SolrSortCode2,isNewProduct
HybrisHelp
  • 5,518
  • 2
  • 27
  • 65