mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
removing exported search methods from redis and mongo
This commit is contained in:
@@ -112,53 +112,6 @@
|
|||||||
// Exported functions
|
// Exported functions
|
||||||
//
|
//
|
||||||
|
|
||||||
module.searchIndex = function(key, content, id) {
|
|
||||||
|
|
||||||
var data = {
|
|
||||||
id:id,
|
|
||||||
key:key,
|
|
||||||
content:content
|
|
||||||
};
|
|
||||||
|
|
||||||
db.collection('search').update({id:id, key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) {
|
|
||||||
if(err) {
|
|
||||||
winston.error('Error indexing ' + err.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.search = function(key, term, limit, callback) {
|
|
||||||
db.command({text:"search" , search: term, filter: {key:key}, limit: limit }, function(err, result) {
|
|
||||||
if(err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!result) {
|
|
||||||
return callback(null, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result.results && result.results.length) {
|
|
||||||
var data = result.results.map(function(item) {
|
|
||||||
return item.obj.id;
|
|
||||||
});
|
|
||||||
callback(null, data);
|
|
||||||
} else {
|
|
||||||
callback(null, []);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.searchRemove = function(key, id, callback) {
|
|
||||||
db.collection('search').remove({id:id, key:key}, function(err, result) {
|
|
||||||
if(err) {
|
|
||||||
winston.error('Error removing search ' + err.message);
|
|
||||||
}
|
|
||||||
if (typeof callback === 'function') {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.flushdb = function(callback) {
|
module.flushdb = function(callback) {
|
||||||
db.dropDatabase(function(err, result) {
|
db.dropDatabase(function(err, result) {
|
||||||
if(err){
|
if(err){
|
||||||
|
|||||||
@@ -9,13 +9,11 @@
|
|||||||
utils = require('./../../public/src/utils.js'),
|
utils = require('./../../public/src/utils.js'),
|
||||||
redis,
|
redis,
|
||||||
connectRedis,
|
connectRedis,
|
||||||
reds,
|
|
||||||
redisClient;
|
redisClient;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
redis = require('redis');
|
redis = require('redis');
|
||||||
connectRedis = require('connect-redis')(express);
|
connectRedis = require('connect-redis')(express);
|
||||||
reds = require('reds');
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
winston.error('Unable to initialize Redis! Is Redis installed? Error :' + err.message);
|
winston.error('Unable to initialize Redis! Is Redis installed? Error :' + err.message);
|
||||||
process.exit();
|
process.exit();
|
||||||
@@ -49,14 +47,6 @@
|
|||||||
ttl: 60 * 60 * 24 * 14
|
ttl: 60 * 60 * 24 * 14
|
||||||
});
|
});
|
||||||
|
|
||||||
reds.createClient = function () {
|
|
||||||
return reds.client || (reds.client = redisClient);
|
|
||||||
};
|
|
||||||
|
|
||||||
var userSearch = reds.createSearch('nodebbusersearch'),
|
|
||||||
postSearch = reds.createSearch('nodebbpostsearch'),
|
|
||||||
topicSearch = reds.createSearch('nodebbtopicsearch');
|
|
||||||
|
|
||||||
var db = parseInt(nconf.get('redis:database'), 10);
|
var db = parseInt(nconf.get('redis:database'), 10);
|
||||||
|
|
||||||
if (db){
|
if (db){
|
||||||
@@ -75,47 +65,6 @@
|
|||||||
//
|
//
|
||||||
// Exported functions
|
// Exported functions
|
||||||
//
|
//
|
||||||
module.searchIndex = function(key, content, id) {
|
|
||||||
if(key === 'post') {
|
|
||||||
postSearch.index(content, id);
|
|
||||||
} else if(key === 'topic') {
|
|
||||||
topicSearch.index(content, id);
|
|
||||||
} else if(key === 'user') {
|
|
||||||
userSearch.index(content, id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.search = function(key, term, limit, callback) {
|
|
||||||
function search(searchObj, callback) {
|
|
||||||
searchObj
|
|
||||||
.query(term)
|
|
||||||
.between(0, limit - 1)
|
|
||||||
.type('or')
|
|
||||||
.end(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(key === 'post') {
|
|
||||||
search(postSearch, callback);
|
|
||||||
} else if(key === 'topic') {
|
|
||||||
search(topicSearch, callback);
|
|
||||||
} else if(key === 'user') {
|
|
||||||
search(userSearch, callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.searchRemove = function(key, id, callback) {
|
|
||||||
if(key === 'post') {
|
|
||||||
postSearch.remove(id);
|
|
||||||
} else if(key === 'topic') {
|
|
||||||
topicSearch.remove(id);
|
|
||||||
} else if(key === 'user') {
|
|
||||||
userSearch.remove(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.flushdb = function(callback) {
|
module.flushdb = function(callback) {
|
||||||
redisClient.send_command('flushdb', [], function(err) {
|
redisClient.send_command('flushdb', [], function(err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user