upgrade tags to sorted set

This commit is contained in:
barisusakli
2014-05-22 13:06:19 -04:00
parent 853acaa6c7
commit 746df87d89
7 changed files with 105 additions and 47 deletions

View File

@@ -19,8 +19,8 @@ module.exports = function(db, module) {
db.collection('objects').remove({_key:key, value:value}, helpers.done(callback));
};
function getSortedSetRange(key, start, stop, sort, callback) {
db.collection('objects').find({_key:key}, {fields:{value:1}})
function getSortedSetRange(key, start, stop, sort, withScores, callback) {
db.collection('objects').find({_key:key}, {fields: {_id: 0, value: 1, score: 1}})
.limit(stop - start + 1)
.skip(start)
.sort({score: sort})
@@ -29,20 +29,26 @@ module.exports = function(db, module) {
return callback(err, null);
}
data = data.map(function(item) {
return item.value;
});
if (!withScores) {
data = data.map(function(item) {
return item.value;
});
}
callback(null, data);
});
}
module.getSortedSetRange = function(key, start, stop, callback) {
getSortedSetRange(key, start, stop, 1, callback);
getSortedSetRange(key, start, stop, 1, false, callback);
};
module.getSortedSetRevRange = function(key, start, stop, callback) {
getSortedSetRange(key, start, stop, -1, callback);
getSortedSetRange(key, start, stop, -1, false, callback);
};
module.getSortedSetRevRangeWithScores = function(key, start, stop, callback) {
getSortedSetRange(key, start, stop, -1, true, callback)
};
module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {