Sort Solr in a dynamic column

I want to solve the problem associated with sorting based on products in a category:

I have 3 tables

Product

|-------id----------|-----name-------| | p1 | Prod 1 | | p2 | Prod 2 | | p3 | Prod 3 | | p4 | Prod 4 | | p5 | Prod 5 | |-------------------|----------------| 

Category

 |-------id----------|-----name-------| | c1 | Cat 1 | | c2 | Cat 2 | | c3 | Cat 3 | | c4 | Cat 4 | |-------------------|----------------| 

PRODUCT_CATEGORY

 |-----prod id-------|-----cat id-----|----score----| | p1 | c1 | 120 | | p1 | c2 | 130 | | p2 | c1 | 150 | | p2 | c3 | 120 | | p2 | c2 | 140 | | p3 | c2 | 180 | | p3 | c3 | 160 | |-------------------|----------------|-------------| 

This means that I have products listed in several categories. I have a page for generating lists dynamically for each category for solr.

Currently my solr doc looks like

 { product_id:p1, category_id:[c1, c2] } 

The problem that I am facing now is the need to sort based on the weight of the product category, that is, products p2, p1 will be indicated on the page of list c1, and list c3 will be p3, p2, p1 (decreasing order of evaluation)

If you change the circuit as a doc, look like

 { product_id:p1, category_id:[c1, c2], c1_weight: 120, c2_weight: 130 } 

Thus, I need to add the cx_weight field to the schema every time we add a new category so that I can sort the cx_weight field.

Let me know a solution in which I can use the solr sorting mechanism to sort by category weight and not change the scheme every time I add a category.

Thanks Dheerendra

+5
source share
1 answer

Why not try modeling your solr doc as a Product_Category string?

 { product_id:p1, category_id:c1, weight:120 }, { product_id:p1, category_id:c2, weight:130 } 

This will support your category requirements.

The only complicating factors appear if you are looking for some kind of product attribute and must be deduplicated by category (see the document collapsing field for this)

+2
source

Source: https://habr.com/ru/post/1244099/


All Articles