reindex all call

v1.18.x
Baris Soner Usakli 12 years ago
parent 0561710016
commit f0759863e6

@ -412,4 +412,28 @@ var RDB = require('./redis.js'),
}); });
} }
Posts.reIndexPids = function(pids, callback) {
function reIndex(pid, callback) {
Posts.getPostField(pid, 'content', function(content) {
search.remove(pid, function() {
if(content && content.length) {
search.index(content, pid);
}
callback(null);
});
});
}
async.each(pids, reIndex, function(err) {
if(err) {
callback(err, null);
} else {
callback(null, 'Posts reindexed');
}
});
}
}(exports)); }(exports));

@ -677,4 +677,37 @@ marked.setOptions({
RDB.lrange('tid:' + tid + ':posts', 0, -1, callback); RDB.lrange('tid:' + tid + ':posts', 0, -1, callback);
} }
Topics.reIndexTopic = function(tid, callback) {
Topics.getPids(tid, function(err, pids) {
if(err) {
callback(err);
} else {
posts.reIndexPids(pids, function(err) {
if(err) {
callback(err);
} else {
callback(null);
}
});
}
});
}
Topics.reIndexAll = function(callback) {
RDB.smembers('topics:tid', function(err, tids) {
if(err) {
callback(err, null);
} else {
async.each(tids, Topics.reIndexTopic, function(err) {
if(err) {
callback(err, null);
} else {
callback(null, 'All topics reindexed.');
}
});
}
});
}
}(exports)); }(exports));

@ -394,6 +394,16 @@ var express = require('express'),
res.send(header + app.create_route("search/"+req.params.term, null, "search") + templates['footer']); res.send(header + app.create_route("search/"+req.params.term, null, "search") + templates['footer']);
}); });
}); });
app.get('/reindex', function(req, res) {
topics.reIndexAll(function(err) {
if(err) {
res.json(err);
} else {
res.send('All topics reindexed');
}
});
});
}); });
}(WebServer)); }(WebServer));

Loading…
Cancel
Save