-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
50 lines (40 loc) · 1.51 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var Resource = require('deployd/lib/resource');
var mongojs = require('mongojs');
util = require('util') ;
function Search(name, options) {
Resource.apply(this, arguments);
if (options && options.db) {
this.dbOpts = options.db.options;
}
process.server.searchCollections = process.server.searchCollections || {};
}
module.exports = Search;
util.inherits(Search, Resource);
Search.basicDashboard = {
settings: [{
name: 'collection',
type: 'text',
description: "the name of the collection to search"
}]
};
Search.label = "Search";
Search.prototype.handle = function (ctx, next) {
switch(ctx.method) {
case "GET":
if(!process.server.searchCollections[this.config.collection]) {
console.log("new con");
var dbOpts = this.dbOpts;
var db = mongojs( dbOpts.credentials.username + ':'+
dbOpts.credentials.password + '@' +
dbOpts.host + ':' + dbOpts.port +'/' +
dbOpts.name);
process.server.searchCollections[this.config.collection] = db.collection(this.config.collection);
}
var collection = process.server.searchCollections[this.config.collection];
collection.runCommand( "text", ctx.query, function(err, res) {
ctx.done(err, res);
});
break;
}
};
Search.prototype.clientGeneration = true;