user search uses reds now

v1.18.x
Baris Usakli 12 years ago
parent 1b33b4425b
commit 691b6611d0

@ -7,7 +7,8 @@ var utils = require('./../public/src/utils.js'),
bcrypt = require('bcrypt'),
notifications = require('./notifications.js'),
topics = require('./topics.js'),
async = require('async');
async = require('async'),
userSearch = require('reds').createSearch('nodebbusersearch');
(function(User) {
User.create = function(username, password, email, callback) {
@ -90,6 +91,8 @@ var utils = require('./../public/src/utils.js'),
RDB.zadd('users:postcount', 0, uid);
RDB.zadd('users:reputation', 0, uid);
userSearch.index(username, uid);
io.sockets.emit('user.latest', {userslug: userslug, username: username});
if (password !== undefined) {
@ -385,25 +388,42 @@ var utils = require('./../public/src/utils.js'),
});
}
User.reIndexAll = function(callback) {
User.getUsers('users:joindate', 0, -1, function(err, usersData) {
if(err) {
return callback(err, null);
}
function reIndexUser(uid, username) {
userSearch.remove(uid, function(){
userSearch.index(username, uid);
})
}
for(var i=0; i<usersData.length; ++i) {
reIndexUser(usersData[i].uid, usersData[i].username);
}
callback(null, 1);
});
}
User.search = function(username, callback) {
if(!username) {
callback([]);
return;
}
RDB.keys('username:*'+ username + '*:uid', function(err, keys) {
if(!err) {
if(keys && keys.length) {
RDB.mget(keys, function(err, uids) {
User.getDataForUsers(uids, function(userdata) {
callback(userdata);
});
});
} else {
callback([]);
}
} else {
userSearch.query(query = username).type('or').end(function(err, uids) {
if(err) {
console.log(err);
return;
}
if(uids && uids.length) {
User.getDataForUsers(uids, function(userdata) {
callback(userdata);
});
} else {
callback([]);
}
});
}

@ -403,10 +403,16 @@ var express = require('express'),
app.get('/reindex', function(req, res) {
topics.reIndexAll(function(err) {
if(err) {
res.json(err);
} else {
res.send('All topics reindexed');
return res.json(err);
}
user.reIndexAll(function(err) {
if(err) {
return res.json(err);
} else {
res.send('Topics and users reindexed');
}
});
});
});

Loading…
Cancel
Save