mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Query sphinx search if configured.
This commit is contained in:
parent
9702c91127
commit
61bf5824ac
3 changed files with 23 additions and 0 deletions
|
@ -77,6 +77,7 @@
|
|||
"mongodb": "^2.0.28",
|
||||
"mongoose": "4.5.3",
|
||||
"mongoose-cache": "https://github.com/nwinter/mongoose-cache/tarball/master",
|
||||
"mysql": "^2.11.1",
|
||||
"node-force-domain": "~0.1.0",
|
||||
"node-gyp": "~0.13.0",
|
||||
"node-statsd": "^0.1.1",
|
||||
|
|
|
@ -712,6 +712,26 @@ UserHandler = class UserHandler extends Handler
|
|||
@sendSuccess res, remark
|
||||
|
||||
searchForUser: (req, res) ->
|
||||
return mongoSearchForUser(req,res) unless config.sphinxServer
|
||||
mysql = require('mysql');
|
||||
connection = mysql.createConnection
|
||||
host: config.sphinxServer
|
||||
port: 9306
|
||||
connection.connect()
|
||||
q = req.body.search;
|
||||
mysqlq = "SELECT *, WEIGHT() as skey FROM user WHERE MATCH(?);"
|
||||
connection.query mysqlq, [q], (err, rows, fields) =>
|
||||
return @sendDatabaseError res, err if err
|
||||
ids = rows.map (r) -> r.mongoid
|
||||
User.find({_id: {$in: ids}}).select({name: 1, email: 1, dateCreated: 1}).lean().exec (err, users) =>
|
||||
return @sendDatabaseError res, err if err
|
||||
out = _.filter _.map ids, (id) => _.find(users, (u) -> String(u._id) is id)
|
||||
console.log(out)
|
||||
@sendSuccess res, out
|
||||
connection.end()
|
||||
|
||||
|
||||
mongoSearchForUser: (req, res) ->
|
||||
# TODO: also somehow search the CLAs to find a match amongst those fields and to find GitHub ids
|
||||
return @sendForbiddenError(res) unless req.user?.isAdmin()
|
||||
search = req.body.search
|
||||
|
|
|
@ -36,6 +36,8 @@ if process.env.COCO_MONGO_LS_REPLICA_STRING?
|
|||
if process.env.COCO_MONGO_LS_AUX_REPLICA_STRING?
|
||||
config.mongo.level_session_aux_replica_string = process.env.COCO_MONGO_LS_AUX_REPLICA_STRING
|
||||
|
||||
config.sphinxServer = process.env.COCO_SPHINX_SERVER or ''
|
||||
|
||||
config.apple =
|
||||
verifyURL: process.env.COCO_APPLE_VERIFY_URL or 'https://sandbox.itunes.apple.com/verifyReceipt'
|
||||
|
||||
|
|
Loading…
Reference in a new issue