Search code examples
solrsap-commerce-cloudsolrj

Hybris how to index Variant in SOLR


I've started with Electronics accelerator which only indexes base products in SOLR. I have multiple Variant products (which extends from GenericVariantProduct) and I need to display them in the Grid/PLP. How can I change the SOLR indexer query in order to Index Variants too?


Solution

  • This is the query used for electronicsProductType :

    SELECT {PK} FROM {Product} WHERE ({varianttype} IS NULL OR {varianttype} NOT IN ( {{ SELECT {PK} FROM {varianttype} WHERE {code} = 'ElectronicsColorVariantProduct'}}) ) 
                                AND {code} NOT IN( {{ SELECT {code} FROM {GenericVariantProduct} }})
    

    In order to index all the product available on the database you can use the following query :

    SELECT {PK} FROM {Product}
    

    You can use the following Impex to achieve your purpose :

    $solrIndexedType=electronicsProductType
    $searchIndexNamePrefix=electronics
    
    UPDATE SolrIndexerQuery; solrIndexedType(identifier)[unique = true]; identifier[unique = true]        ;query
                           ; $solrIndexedType                          ; $searchIndexNamePrefix-fullQuery ; "SELECT {PK} FROM {Product}"
    

    Adapt it to correspond more to your needs