To enhance my product data filtering capabilities, I aim to implement multiple dynamic filter conditions. The initial format of my raw data is structured as follows:
[{
...,
"_source": {
...,
"categories": [
"home",
"office"
],
...,
"attributes": {
"colors": [
"Red-White-Blue",
"Orange-Red-Black"
]
},
...,
}
}]
Subsequently, I possess another dynamic object with key-value pairs that are generated during runtime. The structure of this object is:
{
selectedFilters: {
categories: ["home", "office", "public"],
colors: ["Red-White-Blue", "Orange-Red-Black", "Blue"],
...
}
}
It is important to note that the existence of certain keys, like the categories array, may vary dynamically. Consequently, the key-value pairs are generated dynamically as well.
My objective is to iterate through all the keys within the selectedFilters
object and locate their corresponding values within the raw data arrays.
For instance, if selectedFilters
contains categories
as home
and colors
as white
, then all products categorized as home with white color should be retrieved from the main product database. If colors
has no specified value, then all products categorized as home should be returned, and vice versa. For instance, if color is white and no category is specified, then all products with white color should be retrieved regardless of category.
Is there a method to achieve this task with or without Lodash?