|
1 | 1 |
|
2 | 2 | const async = require('async'), |
3 | 3 | config = require('./config.js'), |
4 | | - _ = require('underscore'); |
| 4 | + _ = require('underscore'), |
| 5 | + Key = require('./key'); |
5 | 6 |
|
6 | 7 | const CLASSNAME = config.className; |
7 | 8 |
|
@@ -50,7 +51,7 @@ exports.updateSimilarityFor = function(userId, cb){ |
50 | 51 | // initializing variables |
51 | 52 | let userRatedItemIds, itemLiked, itemDisliked, itemLikeDislikeKeys; |
52 | 53 | // setting the redis key for the user's similarity set |
53 | | - const similaritySet = [CLASSNAME,userId,'similaritySet'].join(":"); |
| 54 | + const similaritySet = Key.similaritySet(userId); |
54 | 55 | // creating a combined set with the all of a users likes and dislikes |
55 | 56 | client.sunion([CLASSNAME,'user',userId,'liked'].join(":"),[CLASSNAME,'user',userId,'disliked'].join(":"), function(err, userRatedItemIds){ |
56 | 57 | // if they have rated anything |
@@ -105,7 +106,7 @@ exports.predictFor = function(userId, itemId){ |
105 | 106 | itemId = String(itemId); |
106 | 107 | let finalSimilaritySum = 0.0; |
107 | 108 | let prediction = 0.0; |
108 | | - const similaritySet = [CLASSNAME, userId, 'similaritySet'].join(':'); |
| 109 | + const similaritySet = Key.similaritySet(userId); |
109 | 110 | const likedBySet = [CLASSNAME, 'item', itemId, 'liked'].join(':'); |
110 | 111 | const dislikedBySet = [CLASSNAME, 'item', itemId, 'disliked'].join(':'); |
111 | 112 |
|
@@ -160,8 +161,8 @@ exports.updateRecommendationsFor = function(userId, cb){ |
160 | 161 | // initializing the redis keys for temp sets, the similarity set and the recommended set |
161 | 162 | const tempSet = [CLASSNAME, userId, 'tempSet'].join(":"); |
162 | 163 | const tempDiffSet = [CLASSNAME, userId, 'tempDiffSet'].join(":"); |
163 | | - const similaritySet = [CLASSNAME, userId, 'similaritySet'].join(":"); |
164 | | - const recommendedSet = [CLASSNAME, userId, 'recommendedSet'].join(":"); |
| 164 | + const similaritySet = Key.similaritySet(userId); |
| 165 | + const recommendedSet = Key.recommendedSet(userId); |
165 | 166 | // returns an array of the users that are most similar within k nearest neighbors |
166 | 167 | client.zrevrange(similaritySet, 0, config.nearestNeighbors-1, function(err, mostSimilarUserIds){ |
167 | 168 | // returns an array of the users that are least simimilar within k nearest neighbors |
|
0 commit comments