diff --git a/src/postTools.js b/src/postTools.js index d79515a480..c01e0f4a8f 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -75,10 +75,6 @@ var winston = require('winston'), events.logPostEdit(uid, pid); - db.searchRemove('post', pid, function() { - db.searchIndex('post', content, pid); - }); - async.parallel([ function(next) { posts.getPostField(pid, 'tid', function(err, tid) { @@ -89,12 +85,12 @@ var winston = require('winston'), topics.setTopicField(tid, 'title', title); topics.setTopicField(tid, 'slug', slug); - - db.searchRemove('topic', tid, function() { - db.searchIndex('topic', title, tid); - }); } + posts.getPostData(pid, function(err, postData) { + plugins.fireHook('action:post.edit', postData); + }); + next(null, { tid: tid, isMainPost: isMainPost @@ -129,7 +125,8 @@ var winston = require('winston'), var success = function() { posts.setPostField(pid, 'deleted', 1); db.decrObjectField('global', 'postCount'); - db.searchRemove('post', pid); + + plugins.fireHook('action:post.delete', pid); events.logPostDelete(uid, pid); @@ -205,7 +202,7 @@ var winston = require('winston'), }); - db.searchIndex('post', postData.content, pid); + plugins.fireHook('action:post.restore', postData); // Restore topic if it is the only post topics.getTopicField(postData.tid, 'postcount', function(err, count) { diff --git a/src/posts.js b/src/posts.js index 88a2d2037c..7103db2047 100644 --- a/src/posts.js +++ b/src/posts.js @@ -87,8 +87,6 @@ var db = require('./database'), plugins.fireHook('action:post.save', postData); - db.searchIndex('post', content, postData.pid); - next(null, postData); }); } @@ -447,28 +445,6 @@ var db = require('./database'), } } - - Posts.reIndexPids = function(pids, callback) { - - function reIndex(pid, next) { - - Posts.getPostField(pid, 'content', function(err, content) { - if(err) { - return next(err); - } - - db.searchRemove('post', pid, function() { - if (content && content.length) { - db.searchIndex('post', content, pid); - } - next(); - }); - }); - } - - async.each(pids, reIndex, callback); - } - // this function should really be called User.getFavouritePosts Posts.getFavourites = function(uid, start, end, callback) { db.getSortedSetRevRange('uid:' + uid + ':favourites', start, end, function(err, pids) { diff --git a/src/routes/api.js b/src/routes/api.js index 3a62e1b417..5942f995f5 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -402,7 +402,10 @@ var path = require('path'), var limit = 50; function searchPosts(callback) { - db.search('post', req.params.term, limit, function(err, pids) { + Plugins.fireHook('filter:search.query', { + index: 'post', + query: req.params.terms + }, function(err, pids) { if (err) { return callback(err, null); } @@ -412,7 +415,10 @@ var path = require('path'), } function searchTopics(callback) { - db.search('topic', req.params.term, limit, function(err, tids) { + Plugins.fireHook('filter:search.query', { + index: 'topic', + query: req.params.terms + }, function(err, tids) { if (err) { return callback(err, null); } diff --git a/src/routes/debug.js b/src/routes/debug.js index 56a97bb894..7d877c8724 100644 --- a/src/routes/debug.js +++ b/src/routes/debug.js @@ -24,7 +24,6 @@ var DebugRoute = function(app) { }); }); - app.get('/cid/:cid', function (req, res) { categories.getCategoryData(req.params.cid, function (err, data) { if (data) { @@ -55,24 +54,6 @@ var DebugRoute = function(app) { }); }); - app.get('/groups/prune', function(req, res) { - var Groups = require('../groups'); - - Groups.prune(function(err) { - res.send('pruned'); - }); - }); - - app.get('/reindex', function (req, res) { - topics.reIndexAll(function (err) { - if (err) { - return res.json(err); - } else { - res.send('Topics and users reindexed'); - } - }); - }); - app.get('/test', function(req, res) { // categories.getModerators(1, function(err, mods) { // res.json(mods); diff --git a/src/threadTools.js b/src/threadTools.js index 81eb9ff2d0..f99f5f7ef6 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -11,7 +11,8 @@ var winston = require('winston'), posts = require('./posts'), meta = require('./meta'), websockets = require('./socket.io'), - events = require('./events'); + events = require('./events'), + Plugins = require('./plugins'); (function(ThreadTools) { @@ -76,7 +77,7 @@ var winston = require('winston'), ThreadTools.lock(tid); - db.searchRemove('topic', tid); + Plugins.fireHook('action:topic.delete', tid); events.logTopicDelete(uid, tid); @@ -120,9 +121,7 @@ var winston = require('winston'), tid: tid }); - topics.getTopicField(tid, 'title', function(err, title) { - db.searchIndex('topic', title, tid); - }); + Plugins.fireHook('action:topic.restore', tid); callback(null, { tid:tid diff --git a/src/topics.js b/src/topics.js index f285db24b9..bdcd055526 100644 --- a/src/topics.js +++ b/src/topics.js @@ -16,7 +16,8 @@ var async = require('async'), postTools = require('./postTools'), notifications = require('./notifications'), favourites = require('./favourites'), - meta = require('./meta'); + meta = require('./meta'), + Plugins = require('./plugins'); (function(Topics) { @@ -48,7 +49,7 @@ var async = require('async'), } db.sortedSetAdd('topics:tid', timestamp, tid); - db.searchIndex('topic', title, tid); + Plugins.fireHook('action:topic.save', tid); user.addTopicIdToUser(uid, tid, timestamp); @@ -1209,25 +1210,4 @@ var async = require('async'), ], callback); }); }; - - Topics.reIndexTopic = function(tid, callback) { - Topics.getPids(tid, function(err, pids) { - if (err) { - return callback(err); - } - - posts.reIndexPids(pids, callback); - }); - } - - Topics.reIndexAll = function(callback) { - db.getSortedSetRange('topics:tid', 0, -1, function(err, tids) { - if (err) { - return callback(err); - } - - async.each(tids, Topics.reIndexTopic, callback); - }); - } - }(exports));