|
|
@ -4,6 +4,7 @@
|
|
|
|
var async = require('async'),
|
|
|
|
var async = require('async'),
|
|
|
|
db = require('../database'),
|
|
|
|
db = require('../database'),
|
|
|
|
meta = require('../meta'),
|
|
|
|
meta = require('../meta'),
|
|
|
|
|
|
|
|
plugins = require('../plugins'),
|
|
|
|
utils = require('../../public/src/utils');
|
|
|
|
utils = require('../../public/src/utils');
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function(Topics) {
|
|
|
|
module.exports = function(Topics) {
|
|
|
@ -15,10 +16,15 @@ module.exports = function(Topics) {
|
|
|
|
return callback();
|
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tags = tags.slice(0, meta.config.tagsPerTopic || 5);
|
|
|
|
plugins.fireHook('filter:tags.filter', {tags: tags, tid: tid}, function(err, data) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tags = data.tags.slice(0, meta.config.tagsPerTopic || 5);
|
|
|
|
|
|
|
|
|
|
|
|
async.each(tags, function(tag, next) {
|
|
|
|
async.each(tags, function(tag, next) {
|
|
|
|
tag = cleanUpTag(tag);
|
|
|
|
tag = Topics.cleanUpTag(tag);
|
|
|
|
|
|
|
|
|
|
|
|
if (tag.length < (meta.config.minimumTagLength || 3)) {
|
|
|
|
if (tag.length < (meta.config.minimumTagLength || 3)) {
|
|
|
|
return next();
|
|
|
|
return next();
|
|
|
@ -32,9 +38,10 @@ module.exports = function(Topics) {
|
|
|
|
next(err);
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, callback);
|
|
|
|
}, callback);
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function cleanUpTag(tag) {
|
|
|
|
Topics.cleanUpTag = function(tag) {
|
|
|
|
if (typeof tag !== 'string' || !tag.length ) {
|
|
|
|
if (typeof tag !== 'string' || !tag.length ) {
|
|
|
|
return '';
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -47,7 +54,7 @@ module.exports = function(Topics) {
|
|
|
|
tag = matches[1];
|
|
|
|
tag = matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tag;
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function updateTagCount(tag) {
|
|
|
|
function updateTagCount(tag) {
|
|
|
|
Topics.getTagTopicCount(tag, function(err, count) {
|
|
|
|
Topics.getTagTopicCount(tag, function(err, count) {
|
|
|
@ -127,20 +134,28 @@ module.exports = function(Topics) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Topics.searchTags = function(query, callback) {
|
|
|
|
Topics.searchTags = function(data, callback) {
|
|
|
|
if (!query || query.length === 0) {
|
|
|
|
if (!data) {
|
|
|
|
return callback(null, []);
|
|
|
|
return callback(null, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.getSortedSetRevRange('tags:topic:count', 0, -1, function(err, tags) {
|
|
|
|
if (plugins.hasListeners('filter:tags.category')) {
|
|
|
|
|
|
|
|
plugins.fireHook('filter:tags.category', {tags: [], cid: data.cid}, function(err, data) {
|
|
|
|
|
|
|
|
doSearch(err, data ? data.tags : null);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
db.getSortedSetRevRange('tags:topic:count', 0, -1, doSearch);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function doSearch(err, tags) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
return callback(null, []);
|
|
|
|
return callback(null, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
query = query.toLowerCase();
|
|
|
|
data.query = data.query.toLowerCase();
|
|
|
|
var matches = [];
|
|
|
|
var matches = [];
|
|
|
|
for(var i=0; i<tags.length; ++i) {
|
|
|
|
for(var i=0; i<tags.length; ++i) {
|
|
|
|
if (tags[i].toLowerCase().indexOf(query) === 0) {
|
|
|
|
if (tags[i].toLowerCase().indexOf(data.query) === 0) {
|
|
|
|
matches.push(tags[i]);
|
|
|
|
matches.push(tags[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -150,7 +165,7 @@ module.exports = function(Topics) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
callback(null, matches);
|
|
|
|
callback(null, matches);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|