Skip to content

Commit 2299335

Browse files
authored
Merge pull request #2 from ZnPdCo/patch-2
refactor
2 parents 0e053a1 + 66a3ac6 commit 2299335

File tree

9 files changed

+1860
-195
lines changed

9 files changed

+1860
-195
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vscode/
2+
.DS_Store
3+
.env
4+
.well-known/
5+
node_modules/

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# elasticsearch-config
22

3+
部署需要有 es 环境并安装好 ik 与 pinyin 插件,并将 `/plugins/ik/config/stopword.dic``/plugins/ik/config/extra_stopword.dic` 内容清空(禁用停用词):
4+
5+
```
6+
npm install
7+
git clone https://github.com/OI-wiki/OI-wiki.git /home/ubuntu/OI-wiki
8+
cd /home/ubuntu/OI-wiki
9+
git remote add gh https://github.com/OI-wiki/OI-wiki.git
10+
```
11+
12+
初始化并启动 webhook:
13+
14+
```
15+
npm run webhook
16+
```
17+
18+
测试:
19+
20+
```
21+
npm run test
22+
```
23+
24+
启动 api 接口:
25+
26+
```
27+
npm run serve
28+
```
29+
330
统计:
431

532
```

api/main.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,16 @@ app.get('/', function(req, res) {
100100
.then(results => {
101101
results = results.hits.hits;
102102
results = results.map((e) => {
103+
let highlight = [];
104+
if (!e.highlight || !e.highlight.content) {
105+
highlight = [e._source.content.substring(0, 50)];
106+
} else {
107+
highlight = e.highlight.content;
108+
}
103109
return {
104110
url: e._source.url,
105111
title: e._source.title,
106-
highlight: e.highlight.content
112+
highlight: highlight
107113
}
108114
});
109115
res.send(results);

build.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
curl -X DELETE "http://localhost:9200/oiwiki"
2+
curl -H'Content-Type: application/json' -XPUT "http://localhost:9200/oiwiki" -d'
3+
{
4+
"settings": {
5+
"analysis": {
6+
"analyzer": {
7+
"default": {
8+
"tokenizer": "ik_max_word",
9+
"filter": "custom_pinyin"
10+
},
11+
"default_search": {
12+
"tokenizer": "ik_max_word"
13+
}
14+
},
15+
"filter": {
16+
"custom_pinyin": {
17+
"type": "pinyin",
18+
"keep_original": true,
19+
"limit_first_letter_length": 16
20+
}
21+
}
22+
}
23+
}
24+
}'

0 commit comments

Comments
 (0)