Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3319322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:48:40+00:00 2026-05-17T22:48:40+00:00

I want to implement a ranking system on a website I’ve been working on

  • 0

I want to implement a ranking system on a website I’ve been working on and have decided to go with the Hacker News algorithm. My reasoning for choosing this algorithm is simply because it’s been described here.

I was looking at this Python code (the language I’m using to build my site) and couldn’t figure out how I would implement it.

def calculate_score(votes, item_hour_age, gravity=1.8):
    return (votes - 1) / pow((item_hour_age+2), gravity)

Given the tables:

posts:
    id | title | time_submitted

votes:
    id | postid | userid | score

How would I pull the data from the database? The ideal solution (most efficient) would be to construct a MySQL query to retrieve the top 10 posts ranked using the algorithm. But given that Hacker News has it implemented in Arc, it makes me think they pull out all the posts then run them through the algorithm to rank them.

Reddit also comes to mind for this… They use a non-relational database schema so I would assume they, like Hacker News, perform the rankings in their code – not the database.

How would you implement this?

EDIT: one post can have many votes as I would like to log which user votes on which post.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:48:41+00:00Added an answer on May 17, 2026 at 10:48 pm

    You can use the data you need in the ORDER BY clause.

    SELECT p.id, p.title, p.time_submitted, SUM(v.score) as num_votes 
      FROM posts p, votes v
     WHERE v.postid = p.id
    GROUP BY p.id
    ORDER BY 
       (SUM(v.score) - 1) / POW(TIMESTAMPDIFF(HOUR,p.time_submitted,NOW()) + INTERVAL 2 HOUR, 1.8) DESC
    LIMIT 100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a commenting system for my website. I looked around and
i starter in jqgrid, i want implement inline edit in jqgrid i have this
i have question for example i want to implement binary tree with array i
I want to implement a minor file system like collection in MongoDB . So
I want to implement UITableView Where I want to have 3 buttons in each
I run a music website for amateur musicians where we have a rating system
I have WSDL and XSD files and want implement a webservice based on this
I want to implement search functionality for a website (assume it is similar to
I want to implement an automatic update system for a windows application. Right now
I want to implement a paperless filing system and was looking to use WIA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.