S
S
squadbrodyaga2021-04-27 09:37:55
Online shopping
squadbrodyaga, 2021-04-27 09:37:55

Where can I get data for the filter for goods in the online store?

Hello, in general I won’t buy how the product filtering system works in online stores.

Let's say in the database I have a category "Smartphones"

{
  smartphones: [
    {
        "name": "iPhone 12 Mini",
        "price": 62000,
        "color": "black",
        "manufacturer": "Apple"
    },
    {
        "name": "Samsung Galaxy Fold",
        "price": 74000,
        "color": "white",
        "manufacturer": "Samsung"
    },
    ..........
  ]
}

Now I want to understand where to get the data from to filter these phones, here are my options:

1. You need to create an algorithm that will run through the array of phones and get all the keys and values, and based on them generate another array / object, for a filter with something like this structure:
dataForFilter = {
  color: ['black', 'white'],
  manufacturer: ['Apple', 'Samsung']
  ...
}

But there are disadvantages: Firstly, it looks complicated, and secondly, I still don’t understand how to make types for these filters, for example, how to “explain” to the algorithm which key should be as a checkbox, and which one should be as an input, so that later this filter will be rendered on page.

2 . Create for each product category (Phones, laptops, etc.) your own filter manually, which will look something like this:
{
  smartphones: {
     productList: [ ... тот же массив телефонов ... ],
     productFilter: [ 
       {
         name: "color",
         type: "checkbox",
         value: ["white", "black"] 
       },
       {
         name: "manufacturer",
         type: "checkbox",
         value: ["Apple", "Samsung"] 
       }
     ],
  }
}


Or maybe none of my methods come close.
Programmers who understand how the product filtering system works, can you please tell me if the data for the filter is somehow automatically generated or is some poor junior sitting somewhere and filling in the data for the filter manually?

Even better if you show some code snippet)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-04-27
@squadbrodyaga

Google for "faceted search". Typically, this function is performed by a full-text search engine that does the first paragraph for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question