Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

323
Visualizações
Simple popular/trending products algorithm for an ecommerce site with Javascript

I am currently building a small ecommerce site and for the home page, I would like to rank the products based on popularity. The product schema has the following data:

{
  ...
  noViews: Number,  // Number of times a user has clicked on the product
  avgRating: Number, // Average star rating (1 - 5)
  datePosted: Date // Date the product was posted
}

What is a (relatively) simple algorithm/code I can use to implement this (with Node.js), where the products would be ranked based on popularity (with time taken into consideration so the content isn't stale).

Thank you.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

First of all, you need a time based metric to solve this.

Overall trending products does not make much sense particularly for a ecommerce app.

Lets say, you want to do find the trending products for a particular day (say today).

Now this is not a easy problem to solve. And there is no just 1 direct way to solve it. For each company, one method works!

Ideally , what could be a simple solution here would be to create a score value based on combination of factors. For example, number of buys, number of views, number of clicks and so on.

Here, you have the datePosted parameter. Now, create a date_score for this. So, the basic idea here is a product that was posted yesterday has more score than the one posted a week back. The values you put need to tweaked and checked for your algorithm's customization.

Similarly, implemeent a similar score for avgRating and noViews.

Once you have these scores ready, create weights for these scores. Now the weighted average for these out of 100 is the final score.

So, a final example solution:

  • Date Posted:

    • If Date is in the last 3 days (score = 100)
    • If Date is the last week (score= 75)
    • If Date in the previous week (score = 50)
    • Else default score = 25.
  • Star Rating:

    • (Rating/5 ) *100
  • numberOfViews:

    • Here , you can use percentiles.
    • Lets say max views among all the product is x.
    • Then, the view score is (views/x) *100

Now, handle the corner case of what happens when two scores match.

After this, you can simply order by the score parameter.

Also, make sure everything you do is dynamic as static thresholds dont provide a great resul generally!

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda