Can Solr retrieve values from children fields and associate the calculated value with the parent in result?

StackOverflow https://stackoverflow.com/questions/23476570

  •  15-07-2023
  •  | 
  •  

Question

I am using Solr for searching magento products in my project, And i'm indexing Items(simple products) and products(configurable products), I want to know, is it possible for solr to calculate and give back the price of a product based on the minimal price of its sub-products(items);

For instance, i have a product P1 and it is the parent of items m1, m2. i need to get the minimal price from it items, and return it as a price of product P1.

I'm wondering if that is possible. I need to know if solr can do that or if there is a feature or a way to do it ? And finally i thank you!

for example:

{id = 1,
Name=p1,
Price=null,
}
{id = 2,
Name=m2,
Color=blue,
Price=30,
ParentId=1;
}
{id = 3,
Name=p1,
Color=blue,
Price=50,
parentId=1,
}

And If I seek for “p1” I want that p1 will be returned in the result with the price “30” .

regards,

Was it helpful?

Solution

I think you'd either need to do this at during indexing :

Whenever you add a new child, re-index the parent having queried all of its children to find the lowest price.

Or with 2 queries at run time :

Get the parent, if price is null, get the min value of the children.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top