Business requirement

Imagine you have such SAP Commerce business scenario

Product Catalogue with 50,000 products

Your pricing engine supports 2,000 customer groups – meaning there are:

2,000 different groups of prices for your customers

From commerce point of view this would result in having 50,000 * 2,000 = 100,000,000 PriceRows!

100,000,000 PriceRows

Now you have two seemingly simple requirements for your B2B/B2B commerce:

  • show customer-specific price
  • still supporting OOTB feature like price range facets

How would you approach such a case then?

We have to support searching and faceting, thus the idea is to index the prices in search engine. Common case in SAP Commerce would be to represent the customer-group variants of prices as separate fields in SOLR document. This would, however, lead to the creation of documents with thousands of fields. There is generally no hardcoded limit in SOLR for the number of fields per document. Still, this is a known fact that that large documents increase significantly memory consumption an decreases the search and sort performance. That is why let’s try another approach.

Nested documents

Instead of representing the customer group prices as fields, we can use the so-called: Nested objects/documents which allow nesting of documents inside of other documents in a parent-child relationship.

SOLR product document (parent) (notice type_string field) would then look this:

{
        "id":"ProductCatalog/Online/P3450",
        "type_string":"product",
        "_version_":1647953893840125952,
        "pk":8796105703425,
        "catalogId":"ProductCatalog",
        "catalogVersion":"Online",
        ...
}

SOLR nested document (child) (notice type_string field) which represents the customer-group-specific PriceRows would look like:

{
        "id":"P3450_1758",
        "type_string":"price",
        "price_double":10.65,
        "_version_":1647953851039350784
}

Then we can execute search queries on such a large index, with faceting by the nested document properties (like price) or other OOTB functionalities and still get the response within tens of miliseconds even on a non-sharded instance:

curl http://localhost:8983/solr/master_pocShop_Product/query -d '
  q=*:*&
  json.facet={
    prices : {
      type: range,
      field: price_double,
      start : 0,
      end : 100,
      gap : 20
      domain: { blockChildren : "type_string:product" } 
    }
}'
  "responseHeader":{
    "status":0,
    "QTime":79,
    ...
}

Let me know in comments if the topic interested and if you want to know more details about the implementation.


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *