Skip to content

Commit b09bec9

Browse files
committed
feat: add prettier and fmt
1 parent 9e2ba6f commit b09bec9

File tree

6 files changed

+246
-204
lines changed

6 files changed

+246
-204
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ curl -H'Content-Type: application/json' -XPOST "http://localhost:PORT/oiwiki/_de
4444
}'
4545
4646
```
47-

api/main.js

Lines changed: 113 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,132 @@
1-
const elasticsearch = require('elasticsearch');
1+
const elasticsearch = require("elasticsearch");
22
var client = new elasticsearch.Client({
3-
host: 'localhost:9200',
3+
host: "localhost:9200",
44
});
5-
const express = require('express');
6-
const app = express();
5+
const express = require("express");
6+
const app = express();
77

8-
app.set('port', process.env.PORT || 8000);
8+
app.set("port", process.env.PORT || 8000);
99

10-
app.get('/status', function(req, res) {
10+
app.get("/status", function (req, res) {
1111
if (req.query.s == MY_SECRET_KEY) {
12-
client.ping({
13-
requestTimeout: 1000,
14-
}, function (error) {
15-
if (error) {
16-
console.error('elasticsearch cluster is down!');
17-
res.end('elasticsearch cluster is down!');
18-
} else {
19-
console.log('All is well');
20-
res.end('All is well');
21-
}
22-
});
12+
client.ping(
13+
{
14+
requestTimeout: 1000,
15+
},
16+
function (error) {
17+
if (error) {
18+
console.error("elasticsearch cluster is down!");
19+
res.end("elasticsearch cluster is down!");
20+
} else {
21+
console.log("All is well");
22+
res.end("All is well");
23+
}
24+
},
25+
);
2326
}
2427
});
2528

26-
app.get('/', function(req, res) {
29+
app.get("/", function (req, res) {
2730
if (!req.query.s) {
2831
res.send([]);
2932
return;
3033
}
3134
let keyword = req.query.s.slice(0, 50);
3235
console.log(keyword);
33-
client.search({
34-
index: "oiwiki",
35-
from: 0,
36-
size: 12,
37-
body: {
38-
query: {
39-
dis_max: {
40-
queries: [
41-
{
42-
match: {
43-
title: {
44-
query: keyword,
45-
minimum_should_match: "75%",
46-
boost: 4
47-
}
48-
}
49-
},
50-
{
51-
match: {
52-
h2: {
53-
query: keyword,
54-
minimum_should_match: "75%",
55-
boost: 3
56-
}
57-
}
58-
},
59-
{
60-
match: {
61-
content: {
62-
query: keyword,
63-
minimum_should_match: "75%",
64-
boost: 2
65-
}
66-
}
67-
},
68-
{
69-
match: {
70-
url: {
71-
query: keyword,
72-
minimum_should_match: "75%",
73-
boost: 3
74-
}
75-
}
76-
},
77-
{
78-
match: {
79-
standard_content: {
80-
query: keyword,
81-
minimum_should_match: "75%",
82-
boost: 2
83-
}
84-
}
85-
}
86-
],
87-
tie_breaker: 0.3
88-
}
89-
},
90-
highlight: {
91-
pre_tags: ["<em>"],
92-
post_tags: ["</em>"],
93-
fields: {
94-
title: { number_of_fragments: 1 },
95-
h2: { number_of_fragments: 1 },
96-
content: { number_of_fragments: 1 },
97-
url: { number_of_fragments: 1 }
36+
client
37+
.search({
38+
index: "oiwiki",
39+
from: 0,
40+
size: 12,
41+
body: {
42+
query: {
43+
dis_max: {
44+
queries: [
45+
{
46+
match: {
47+
title: {
48+
query: keyword,
49+
minimum_should_match: "75%",
50+
boost: 4,
51+
},
52+
},
53+
},
54+
{
55+
match: {
56+
h2: {
57+
query: keyword,
58+
minimum_should_match: "75%",
59+
boost: 3,
60+
},
61+
},
62+
},
63+
{
64+
match: {
65+
content: {
66+
query: keyword,
67+
minimum_should_match: "75%",
68+
boost: 2,
69+
},
70+
},
71+
},
72+
{
73+
match: {
74+
url: {
75+
query: keyword,
76+
minimum_should_match: "75%",
77+
boost: 3,
78+
},
79+
},
80+
},
81+
{
82+
match: {
83+
standard_content: {
84+
query: keyword,
85+
minimum_should_match: "75%",
86+
boost: 2,
87+
},
88+
},
89+
},
90+
],
91+
tie_breaker: 0.3,
92+
},
9893
},
99-
fragment_size: 20,
100-
}
101-
}
102-
})
103-
.then(results => {
104-
results = results.hits.hits;
105-
results = results.map((e) => {
106-
let highlight = [];
107-
if (!e.highlight || !e.highlight.content) {
108-
highlight = [e._source.content.substring(0, 50)];
109-
} else {
110-
highlight = e.highlight.content;
111-
}
112-
return {
113-
url: e._source.url,
114-
title: e._source.title,
115-
highlight: highlight
116-
}
94+
highlight: {
95+
pre_tags: ["<em>"],
96+
post_tags: ["</em>"],
97+
fields: {
98+
title: { number_of_fragments: 1 },
99+
h2: { number_of_fragments: 1 },
100+
content: { number_of_fragments: 1 },
101+
url: { number_of_fragments: 1 },
102+
},
103+
fragment_size: 20,
104+
},
105+
},
106+
})
107+
.then((results) => {
108+
results = results.hits.hits;
109+
results = results.map((e) => {
110+
let highlight = [];
111+
if (!e.highlight || !e.highlight.content) {
112+
highlight = [e._source.content.substring(0, 50)];
113+
} else {
114+
highlight = e.highlight.content;
115+
}
116+
return {
117+
url: e._source.url,
118+
title: e._source.title,
119+
highlight: highlight,
120+
};
121+
});
122+
res.send(results);
123+
})
124+
.catch((err) => {
125+
console.log(err);
126+
res.send([]);
117127
});
118-
res.send(results);
119-
})
120-
.catch(err=> {
121-
console.log(err);
122-
res.send([]);
123-
});
124128
});
125129

126-
app.listen(app.get('port'), function() {
127-
console.log('Search server running on port ' + app.get('port'));
130+
app.listen(app.get("port"), function () {
131+
console.log("Search server running on port " + app.get("port"));
128132
});
129-

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"serve": "node api/main.js",
88
"webhook": "node webhook/index.js",
9-
"test": "node webhook/test.js"
9+
"test": "node webhook/test.js",
10+
"format": "npx prettier . --write"
1011
},
1112
"keywords": [
1213
"OI",
@@ -24,5 +25,8 @@
2425
"simple-git": "^3.26.0",
2526
"strip-markdown-math": "^3.0.3",
2627
"yaml": "^2.5.1"
28+
},
29+
"devDependencies": {
30+
"prettier": "^3.4.2"
2731
}
2832
}

0 commit comments

Comments
 (0)