'How is user search made relevant with first degree connections?

On any social media platform when I search for users, I get results sorted by count of mutual connections (first degree connections)

Lets say I search for a user named "Rishi" As shown in attached image below Rishi Xyz was top suggestion as we had 10 mutual connections Followed by others descending

help

For full text searches we could always use elastic search, but how do we sort them on mutual connections

How would this scale for millions of users

Any relevant articles where I can study more about its implementation could help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source