Again, working on my current project, one of the things it offers is the ability to define another user as your friend (and you their friend). My site isn't social networking, but has some features in common, such as defining friendship relationships.

Now, it's easy to create a simple three column table of user IDs (one column is a unique key, the next two are the two users that are friends) and do a quick search to see if two people have agreed to be friends. SELECT * FROM friends WHERE (column A = X and Column B = Y) or (Column A = Y and Column B = X). If you get a result with more than zero rows, X and Y are friends.

Where it gets hairy is determining friend of a friend (FOAF) relationships. Let's say I have 100 unique friends. Combing through all the friend lists of 100 people is a lot of load on the database server. It's a query for my friends list, then 100 more queries for the friends lists of each of my friends, then trying to match the other person against that big list. Or at least, that's the first solution that comes to mind.

If you think about it, there's a much faster way that requires only two queries. Query 1, get my friend list. Query 2, get the other person's friend list. Then feed it to a function that compares the lists. If there's a match, we're FOAF linked.

Some might ask, why even bother? Well, it may be interesting to persons X and Y to know what friends they have in common or even that they have friends in common. It might help them establish a friendship. It's sort of based on the thinking "the friend of my friend is my friend."

Now, there's an alternate school of thought, that predicting friendship potential is more effective with a "the enemy of my enemy is my friend" process. The rationale is that people have pretty loose criteria for accepting a friendship request on social networks. You may barely like or know someone, but you'll accept their friend invite because a bigger network makes you look more popular... and we all want to be popular.

On the other hand, if you had to define people as enemies... that's a negative, and a lot of people go by "if you can't say something nice, don't say anything at all." So if someone defines someone else as an enemy, it's a lot less likely to be done casually. There's usually some pretty strong emotion there.

If we judge friendship potential based on having friends in common, it may be that we both sent a friend invite to a pretty girl we never met, but she accepted our invites because it couldn't hurt and it boosted her numbers. We get together for beers and we've got NO common ground. If we've both declared the same person an enemy, most likely we can get a couple of beers and talk for hours about how much that person sucks. It may not be the most fuzzy and cuddly beginning to a friendship, but we're bonding.

Of course, because it's so negative, you're not likely to see a social networking site defining enemy relationships. First, a lot of people wouldn't declare their enemies out in the open; not because you don't want to hurt their feelings, but because if they don't know you hate them, they'll never see you coming. ;-)

Second, if you declare them enemies, and they find out, you've now got to be looking over your shoulder for them. Part of what helps many people get through each day alive is letting your enemies remain blissfully unaware of your hatred until you are prepared to strike.

I'd say you might see it on World of Warcraft or within the social aspect of some multiplayer online game where fighting enemies is part of the fun, but in such an instance, it's going to discount enimity, because you're defining someone as an in-game enemy, not a real-life enemy. The guy you hate in real life, you're just going to avoid. But your buddy's 85th level Battle Stenographer... you declare him an enemy and then shout "I keeeel you!!!"

So, "friend of a friend" matching... it's of questionable value, but when you look for intersections between two result sets instead of looking for one ID as a member of 100 result sets, it's relatively economical in terms of resources and why the heck not?

One Response to “Friend of A Friend Searching”
  1. Have you heard about Enemybook? Lets you disconnect from your enemies on Facebook.

    http://www.enemybook.info/

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>