mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-27 01:39:53 +01:00
closes #1996
This commit is contained in:
@@ -132,7 +132,7 @@ function filterAndRenderCategories(req, res, next, active) {
|
||||
}
|
||||
|
||||
adminController.tags.get = function(req, res, next) {
|
||||
topics.getTags(0, -1, function(err, tags) {
|
||||
topics.getTags(0, 99, function(err, tags) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
@@ -47,14 +47,13 @@ tagsController.getTag = function(req, res, next) {
|
||||
};
|
||||
|
||||
tagsController.getTags = function(req, res, next) {
|
||||
topics.getTags(0, -1, function(err, tags) {
|
||||
topics.getTags(0, 99, function(err, tags) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.render('tags', {tags: tags});
|
||||
res.render('tags', {tags: tags, nextStart: 100});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
module.exports = tagsController;
|
||||
|
||||
@@ -518,4 +518,53 @@ SocketTopics.searchTags = function(socket, data, callback) {
|
||||
topics.searchTags(data, callback);
|
||||
};
|
||||
|
||||
SocketTopics.searchAndLoadTags = function(socket, data, callback) {
|
||||
topics.searchTags(data, function(err, tags) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
async.parallel({
|
||||
counts: function(next) {
|
||||
db.sortedSetScores('tags:topic:count', tags, next);
|
||||
},
|
||||
tagData: function(next) {
|
||||
tags = tags.map(function(tag) {
|
||||
return {value: tag};
|
||||
});
|
||||
|
||||
topics.getTagData(tags, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
results.tagData.forEach(function(tag, index) {
|
||||
tag.score = results.counts[index];
|
||||
});
|
||||
results.tagData.sort(function(a, b) {
|
||||
return parseInt(b.score, 10) - parseInt(a.score, 10);
|
||||
});
|
||||
|
||||
callback(null, results.tagData);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
SocketTopics.loadMoreTags = function(socket, data, callback) {
|
||||
if(!data || !data.after) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
var start = parseInt(data.after, 10),
|
||||
end = start + 99;
|
||||
|
||||
topics.getTags(start, end, function(err, tags) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, {tags: tags, nextStart: end + 1});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = SocketTopics;
|
||||
|
||||
@@ -89,11 +89,11 @@ module.exports = function(Topics) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
addTagData(tags, callback);
|
||||
Topics.getTagData(tags, callback);
|
||||
});
|
||||
};
|
||||
|
||||
function addTagData(tags, callback) {
|
||||
Topics.getTagData = function(tags, callback) {
|
||||
var keys = tags.map(function(tag) {
|
||||
return 'tag:' + tag.value;
|
||||
});
|
||||
@@ -109,7 +109,7 @@ module.exports = function(Topics) {
|
||||
});
|
||||
callback(null, tags);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Topics.getTopicTags = function(tid, callback) {
|
||||
db.getSetMembers('topic:' + tid + ':tags', callback);
|
||||
@@ -139,7 +139,7 @@ module.exports = function(Topics) {
|
||||
|
||||
async.parallel({
|
||||
tagData: function(next) {
|
||||
addTagData(tags, next);
|
||||
Topics.getTagData(tags, next);
|
||||
},
|
||||
counts: function(next) {
|
||||
db.sortedSetScores('tags:topic:count', uniqueTopicTags, next);
|
||||
@@ -214,12 +214,13 @@ module.exports = function(Topics) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
|
||||
db.getSortedSetRevRange('tags:topic:count', 0, -1, function(err, tags) {
|
||||
if (err) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
if (data.query === '') {
|
||||
return callback(null, tags);
|
||||
}
|
||||
data.query = data.query.toLowerCase();
|
||||
var matches = [];
|
||||
for(var i=0; i<tags.length; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user