My platform here is Ruby - a webapp using Rails 3.2 in particular.

I'm trying to match objects (people) based on their ratings for certain items. People may rate all, some, or none of the same items as other people. Ratings are integers between 0 and 5. The number of items available to rate, and the number of users, can both be considered to be non-trivial.

A quick illustration -

![Data illustration](https://i.stack.imgur.com/Dkgb0.png)

The brute-force approach is to iterate through all people, calculating differences for each item. In Ruby-flavoured pseudo-code -

```
MATCHES = {}
for each (PERSON in (people except USER)) do
  for each (RATING that PERSON has made) do
    if (USER has rated the item that RATING refers to) do
      MATCHES[PERSON's id] += difference between PERSON's rating and USER's rating
    end
  end
end
lowest values in MATCHES are the best matches for USER

```

The problem here being that as the number of items, ratings, and people increase, this code will take a very significant time to run, and ignoring caching for now, this is code that has to run a lot, since this matching is the primary function of my app.

I'm open to cleverer algorithms and cleverer databases to achieve this, but doing it algorithmically and as such allowing me to keep everything in MySQL or PostgreSQL would make my life a lot easier. The only thing I'd say is that the data does need to persist.

If any more detail would help, please feel free to ask. Any assistance greatly appreciated!