SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating user recommendations

    hi all,

    Basically, i want to create recommendations for the user based on their current 'favourites'. I imagine I would want to look at the favourites of other users and compare to see which would be good for the current user.

    I have a favourites table with columns user_id and content_id just as you would expect.

    I am not asking for code or anything, but just maybe an idea or two on how to go about this. surely comparing all the users favourites with the current user would be quite slow, so I was wondering what methods others have used.

    Many thanks!

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2006
    Location
    Chicago
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To compare other people's favorites against one of your favorites, match that favorite against all the other occurrences in content_id in the table. This will get the users that have that 'favorite' and get all their other favorites. Then, organize them in order of the frequency of which they appear. A "select count" would be helpful here. The most common favorite should appear at the top.

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers for the help!

    Ive come up with something along the lines of this just for now (not checked)
    Code PHP:
    $favourites = array(1, 4, 32, 98); /*just random test data*/
    $recomendations = array();
     
    foreach($favourites as $favourite) {
        $sql = "SELECT user_id FROM favourites WHERE content_id = 1 ORDER BY RAND() LIMIT 10"; /*limit so we don't get too many + order by rand so its not biased*/
        $result = mysql_query($sql);
        while( $row = mysql_fetch_assoc($result) ) {
            $wheres[] = "user_id = ".$row['user_id'];
        }
     
        $where = " WHERE " .implode(" OR ", $wheres); /*prepare the where part of the next query*/
        $sql = "SELECT content_id,COUNT(content_id) as count FROM favourites ".$where." GROUP BY content_id ORDER BY COUNT(content_id) LIMIT 10" /*again limit so we don't have too many results*/
        $result = mysql_query($result);
        while( $row = mysql_fetch_assoc($result) ) {
            $recommendations[$row['content_id']] += $row['count'];
        }
     
    }
     
    arsort($reccomendations); /*should end with a nice array with the highest reccomendation first, a simple foreach should produce the keys in the correct order*/

    would this be a good way to go about it, it involves 2n queries where n is the number of favourites the user currently has, i do not have much experience with that and do not have a biggest enough database to test it on.

    cheers, austin!

  4. #4
    SitePoint Member
    Join Date
    May 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry to bump this thread, but is this the best method for generating 'recommendations' for the user? I can't think of another method but this one seems a bit maybe inefficient. i've tried googling but to no avail.

    thanks very much!

  5. #5
    SitePoint Addict Wildhoney's Avatar
    Join Date
    Apr 2006
    Location
    Nottingham
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you explain what you're trying to achieve in simple terms, please.
    TalkPHP.com - The Friendly PHP Community

    Watch Reaper Online - Watch Chuck Online

  6. #6
    SitePoint Member
    Join Date
    May 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry if i am being too vague/incoherent.

    Basically, a user has a list of favourites and so will many other users. What i want to do is create a list of recommendations for a specific user, ie, things they would enjoy based on their own favourites and people who have similar tastes to them's favourites.

    for example, last.fm gives users recommendations of music to users based on what they have been listening to, and bands the user doesnt listen to, but people who have similar tastes do.

  7. #7
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want something serious, go for Slope One. There's a couple of PHP libraries you can use in your project.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •