forked from kurokikaze/limestone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls-test.js
54 lines (39 loc) · 1.49 KB
/
ls-test.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
51
52
53
54
var http = require("http"),
limestone = require("./limestone").SphinxClient();
http.createServer(function (request, response) {
var timed_out = false;
setTimeout(function() {
timed_out = true;
response.writeHead(500, {"Content-Type": "text/plain"});
response.write("Request timed out\n\n");
response.end();
}, 2000);
response.writeHead(200, {"Content-Type": "text/plain"});
var connect = limestone.connect(9312, function(err) {
if (err) {
response.writeHead(500, {"Content-Type": "text/plain"});
response.write("Connection error\n");
response.end();
} else {
var startDate = (new Date()).getTime();
var query = limestone.query({'query':'test'}, function(err, answer) {
limestone.disconnect();
if (err) {
response.writeHead(500, {"Content-Type": "text/plain"});
response.write("Search error\n");
response.end();
} else {
var endDate = (new Date()).getTime();
body = "Hello World\nDone in " + ((endDate - startDate) / 1000) + " seconds\n\n" + JSON.stringify(answer) + "\n\n";
response.writeHead(200, {
"Content-Length": body.length,
"Content-Type": "text/plain"
});
response.write(body);
response.end();
}
});
}
});
}).listen(8000);
console.log('HTTP server started');