-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
67 lines (56 loc) · 1.6 KB
/
app.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
55
56
57
58
59
60
61
62
63
64
65
66
67
const express = require('express');
var cors = require('cors');
var fs = require('fs');
var https = require('https');
const searchDoc = require('./search');
const app = express();
const bodyparser = require('body-parser');
const port = process.env.PORT || 3200;
app.use(cors());
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({ encoded: false }));
app.get("/search/:version/:text", async (req, res) => {
console.log(`Searching ${req.params.version} for ${req.params.text}`);
const body = {
query: {
"dis_max": {
"queries": [
{
"match": {
"title": {
"query": req.params.text,
"fuzziness": "auto",
"boost": 3
}
}
},
{
"match": {
"body": req.params.text
}
}
],
"tie_breaker": 0.7
}
},
highlight: {
"fields": {
"body": {}
}
}
}
try {
const resp = await searchDoc(req.params.version, body);
res.status(200).send(resp);
} catch (e) {
console.log(e);
res.status(500);
}
})
https.createServer({
key: fs.readFileSync('./server.key'),
cert: fs.readFileSync('./server.cert')
}, app)
.listen(port, () => {
console.log(`Running at port ${port}`);
});