|
|
|
@ -1,28 +1,34 @@
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var db = require('./../database');
|
|
|
|
|
var db = require('../database');
|
|
|
|
|
|
|
|
|
|
module.exports = function(User) {
|
|
|
|
|
User.search = function(query, callback) {
|
|
|
|
|
|
|
|
|
|
User.search = function(query, type, callback) {
|
|
|
|
|
if (!query || query.length === 0) {
|
|
|
|
|
return callback(null, {timing:0, users:[]});
|
|
|
|
|
}
|
|
|
|
|
var start = process.hrtime();
|
|
|
|
|
|
|
|
|
|
db.getObject('username:uid', function(err, usernamesHash) {
|
|
|
|
|
var set = 'username:uid';
|
|
|
|
|
if (type === 'email') {
|
|
|
|
|
set = 'email:uid';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.getObject(set, function(err, hash) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(null, {timing: 0, users:[]});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query = query.toLowerCase();
|
|
|
|
|
|
|
|
|
|
var usernames = Object.keys(usernamesHash);
|
|
|
|
|
var values = Object.keys(hash);
|
|
|
|
|
var uids = [];
|
|
|
|
|
|
|
|
|
|
for(var i=0; i<usernames.length; ++i) {
|
|
|
|
|
if (usernames[i].toLowerCase().indexOf(query) === 0) {
|
|
|
|
|
uids.push(usernames[i]);
|
|
|
|
|
for(var i=0; i<values.length; ++i) {
|
|
|
|
|
if (values[i].toLowerCase().indexOf(query) === 0) {
|
|
|
|
|
uids.push(values[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -31,7 +37,7 @@ module.exports = function(User) {
|
|
|
|
|
return a > b;
|
|
|
|
|
})
|
|
|
|
|
.map(function(username) {
|
|
|
|
|
return usernamesHash[username];
|
|
|
|
|
return hash[username];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
User.getUsers(uids, function(err, userdata) {
|
|
|
|
|