When you start searching for someone in Facebook's search bar, it will automatically start bringing back finds. What is the algorithm here? Is order arbitrary, and if not what determines it?

Edit: My reason for asking is that a friend of mine tried searching for "Rachel", and the first result was a Rachel that was friends with me. Their only common friend is me. Below her was another Rachel with whom he shared more mutual friends. This just seemed peculiar so I was wondering if anyone had some insight into why this might be the case.

13 Answers 13


I don't know for certain (I don't work for Facebook!), but from my experience it seems to bring back results in (approximately) the following order:

  1. From your friends
  2. From your friends friends
  3. People with common interests (liked pages, shared groups etc.)

After this it starts to become more guesswork, but I suspect that home town, shared work places etc all come into play as well.

With more than 500 million users there's a lot of data and existing connections they can use to base their heuristics on


There is a pretty in-depth post about how Facebook Search works posted on Facebook Engineering's page: http://www.facebook.com/note.php?note_id=365915113919

From that, the section Relevance Indicators:

Personal Context: Unlike most search engines, every Facebook search involves two key elements - a query and a querier. Just as we need to understand the query, it’s as essential to understand the person behind the query. People are more likely to be looking for things located in their own city/country or for people who share the same college/workplace. We consider this information and much more when ranking results. The more we know about you, the better your search results will be.

Social Context: An important subset of personal context, social context refers to the people one knows and cares about. The“Jose Gonzales” with whom you have 5 mutual friends is a better result than those with no friends in common. Note that the better job search does at helping you find and connect, the better your search results will be going forward. While personal context makes use of things you care about, social context deals with the things your friends care about. Since calculating social context for every query is technically complex, we built a separate service for it. We will cover the details of this service in a future blog post.

The Query: We tokenize the query based on the suspected language (Chinese tokenized on characters, English on spaces), correct potential spelling mistakes, find "Elizabeth Jones" even though you typed in "Liz Jones," etc. We also prioritize results based on how they matched the query; e.g we rank entities with "chicago" in their title differently from those located in Chicago. We've made good progress in understanding queries, but have a lot more left to do.

Global Popularity: An entity popular amongst a large audience deserves high ranking. Someone searching “Michael Jackson” is more likely to want the pop star than a friend of a friend by the same name. To determine global popularity we look at how many people are connected to an entity as well as how engaged they are -- a Poker application with a few frequent users might be more relevant than one with several infrequent users.

  • 7
    Could you summarise the relevant section here. It guards against link rot (I know this is Facebook, but you never know).
    – ChrisF
    Jan 25, 2011 at 8:00

Here's what I've noticed. Whenever I search for a friend on facebook, I start to type the person's name, and after the first few letters, I get a list of people who's first or last name starts with the letters I've typed. NORMALLY, the list of friends starts with people I'm already friends with, and leads into people who I might possibly know through mutual friends. BUT...

I've recently started dating a guy. Now, when I type in the letter "G" to search my friend Georgia, the first person on my list is my boyfriend's best friend who's last name begins with "G". Then I tried "K" for Kelly. Instead of seeing my friend Kelly who would normally appear, I get a list of people with the last name Keats - my boyfriend's sisters, mother, aunt, and cousins. I haven't visited any of these profiles before, so I'm guessing that they're all checking out mine to see what the new girl is all about. That just goes to show that the search results are based, at least in part, on profile visits.

  • 1
    As a teacher I eventually get every year several friendship requests from students who search and browse my profile (that I don't accept), yet it did never happen to me to see their profile while writing inside the search box. Feb 22, 2017 at 20:24

It's possible that he is more active with you on facebook than with the other friends, which would place the first Rachel higher in the algorithm than the Rachel who is friends with people he doesn't interact with as much.

Again, this is just conjecture as I don't work for Facebook.


I feel it has to do with who views your page, for how long, who you view, for how long, and how frequently you search them. Your friends probably has a somewhat large value to show up first and/or their friends and the value can probably be lowered than a non-friend due to the time factor spent on a non-friend's page. Maybe even clicks is played into the search. There is a complicated formula. Facebook is crazy about this stuff. In the movie, when Mark (facebook CEO) did the site about which girl at school was hot or not, he ask a friend to come up with a formula to determine a winner. With how brilliant facebook has become, I don't doubt for a second that they take into consideration all these factors and 20,000 others when designing this formula.

I liked this guy and I couldn't find his page. Of course he was searching me as well and I'm assuming the reason why I was unable to search him was because he made his page only searchable to friends. (he has a girlfriend that's why and didn't want me to know) When he did allow me to search him, he was the first one after I typed his name. I didn't see this before.


It starts with the letter of input makes a quick query from multiple database's and or tables. Say you start typing v. It looks first for any of your friends names that start with a v. If it finds a friend it then displays it.

I've noticed that if you have a friends page that you visit more often. If you then start typing the first letter it shows that as a first result. So it seems they save your frequently searched allowing them to give you better results.


I can definitely say that there are people who have come up on that list who are not my Facebook friends, and who I have never looked up, and I recognize them from my past. Also, I have an old flame who I looked up and he was at the top of my list there, then he moved to the third one down (all three starting with the letter A), and I didn't look him up again, and then he moved to the top.

Hard to say but I would guess the one's at the top are looking at your profile.


Mutual friends show up first. As you type close to some name and the results are not your friends and you had never visited their profiles, then it is someone who visited you recently.

Also the pages and people you visit the most pop up first.


I am actually almost certain it has to do with people who view your page because I was thinking about this and conducted a little experiment (it's kinda confusing but bear with me).

I started off by typing every letter of the alphabet and seeing who came up on the search. So for example, I typed "A" and saw who came up. I noticed that the list of people were not necessarily in alphabetical order, but the people at the top were certainly my closest friends whose pages I visit all the time.

Then I thought maybe Facebook sets the search bar up conveniently for you to find the people you visit the most. But then I saw something strange, the girl that I just added was actually the second person in the "L" list, the first being my best friend, so that seemed odd to me.

So then I started thinking that it might actually have to do with the people who visit your page. To test the theory, I went to my "C" list, where the top two people were actually pretty much equal in terms of how many times I've visited their page and I assume they've visited mine. I went to the second person in the "C" list and clicked on their page a lot, refreshed it a few good times. Then I went back and searched "C" and sure enough, it was now the second friend whose page I had been refreshing who showed up first. I knew that this second friend was camping and had no Facebook/no way of looking at my page.

Now here's the real kicker: I told my other friend in the "C" list, the one who used to be first when I searched "C" to go on my page a couple of times. She did. I then took a couple of minutes and searched "C" again, and guess who came up first?

That's right, the girl who had just searched my page, despite the fact that I had been looking up the other girl's page recently.

Does this really prove that the Facebook search bar operates on people who have viewed your profile? Maybe, but it could also prove that I have WAY too much time on my hands.


When I go on to my boyfriend's profile and type the letter C in his search bar then the first result is his ex girlfriend, whom he is not friends with on facebook, so I think it can show up the people who look at your page as he swears he's only been on her page once in the last year and a half and yet she shows up ahead of his friends pages. If this is not the case, he'll be single soon!

  • Does this give an in-depth view of how Facebook guesses the search? Jan 6, 2013 at 20:00

I've been watching my friends search for a while..a little OCD... LOL and when I search someone who is a friend on facebook and one who is not a friend the most recent searched person moves to the top. I stopped looking at the one who is not a facebook friend expecting him to move down the list and he did for a while staying steady in the same spot for months then he went to the top of my list for weeks...This happened many times so I finally asked him about it and he denies looking at my profile but I don't believe him. it seems as though facebook keeps track of who you search first then who searches you(unless they look a lot then they go to the 1st position) then anyone you private message then ones you have the most interaction with.


I finally figured out the Facebook search bar trick!! So for years there's been this rumor that the search bar is the key to finding out who views your FB. They say it's just a legend... Not really!! So legend has it that if you type in a letter, the first result is either the person you searched for/looked at last... Or if you never have, that person has looked at you! Or they search for you frequently, or both.

( It also works based on interaction, for friends especially, but I have found this to work for friends who never interact with you, as well as friends of friends who have never had interaction.)

So I conducted a little experiment and found out that the trick does work - but ONLY IF YOU'RE BOTH SEARCHING  for each other! That's the missing link. I had someone view me... Nothing. They were still in position 4 down from the top. I search for someone else, who has not viewed me, and nothing - they're still a low result. But then I search for the person who viewed me on the same day, and boom! Less than 3 hours later, they were result number one when I typed in their first or last name initials!! Incidently, this works for friends, or friends of friends, even those who only have one mutual friend in common with you!

(Important: don't try to cheat by partially typing their name. First initial only, for first or last names! Also, this works for the full-site FB, which I use on my phone as a modification to the mobile FB. It does not work with the iPhone app.)

If you search for someone, friend or not, they will still show in your top 5 results for up to a day or so, then they rank lower and not even show in your top 3 if you don't search again. If you search for someone and they instantly (about 3 hours later) rank 1st after that, they've been searching for/looking at you too! If they eventually drop in ranking, either another one of your friends with the same initials interacted with you recently, or you're the only interested party...

Of course, this will be difficult to track if you're stalking them and click on them several times a day, LOL! But I've found that one single search is enough to set it off. ( I keep track of my searches by using the search log. Clearing your searches can throw off results after a couple of hours, too.) I've tried this experiment on multiple days... Same results. (In case you're wondering where I find the time, the answer is that I don't sleep a lot!)

  • I'm highly dubious.
    – ale
    Dec 25, 2013 at 15:48
  • It's true... I tested it multiple times. Same results.
    – JGirl
    Jan 2, 2014 at 21:14

I believe that it could be someone that recently viewed your profile. No one else has brought this up.

  • Do you have a source for this information? Oct 22, 2013 at 7:35