-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
86 lines (58 loc) · 1.66 KB
/
Copy pathserver.js
File metadata and controls
86 lines (58 loc) · 1.66 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// query data from mongodb
var searchTerm = 'shravan sujay';
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var uri = 'mongodb://localhost/cis550project';
var invertedIndex = [], forwardIndex = [];
var get_InvertedIndex = function (db, callback){
var cursor = db.collection('InvertedIndex').find({} , {_id:0} );
cursor.each(function(err, doc) {
assert.equal(err, null);
if (doc != null) {
invertedIndex.push(doc);
// console.log(invertedIndex);
} else {
// console.log("not found");
callback();
}
});
};
var get_ForwardIndex = function(db, callback){
var cursor = db.collection('node').find({ } , {_id:0} );
cursor.each(function(err, doc) {
assert.equal(err, null);
if (doc != null) {
forwardIndex.push(doc);
//console.log(doc);
//console.log('Converting to keys, hopefully: ' + Object.keys(doc));
} else {
// console.log("not found");
callback();
}
});
}
MongoClient.connect(uri, function(err, db) {
assert.equal(null, err);
get_InvertedIndex(db, function() {
db.close();
});
});
MongoClient.connect(uri, function(err, db) {
assert.equal(null, err);
get_ForwardIndex(db, function() {
db.close();
});
});
var express = require('express'), http = require('http');
var app = express();
tables = {
"invertedIndex": invertedIndex,
"forwardIndex": forwardIndex,
"searchTerm": searchTerm
}
app.use(express.static(__dirname + "/client/"));
http.createServer(app).listen(3000);
console.log("listening on 3000");
app.get("/data", function(req, res){
res.json(tables);
});