Skip to content

Commit 9e2ba6f

Browse files
committed
fix: 添加standard搜索
1 parent 66a3ac6 commit 9e2ba6f

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

api/main.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ app.get('/status', function(req, res) {
2424
});
2525

2626
app.get('/', function(req, res) {
27-
// if (!req.headers.referer || req.headers.referer.indexOf('oi-wiki.org') < 0) {
28-
// res.send([]);
29-
//return;
30-
//}
31-
// console.log(req.headers);
3227
if (!req.query.s) {
3328
res.send([]);
3429
return;
@@ -37,7 +32,6 @@ app.get('/', function(req, res) {
3732
console.log(keyword);
3833
client.search({
3934
index: "oiwiki",
40-
type: "article",
4135
from: 0,
4236
size: 12,
4337
body: {
@@ -79,6 +73,15 @@ app.get('/', function(req, res) {
7973
boost: 3
8074
}
8175
}
76+
},
77+
{
78+
match: {
79+
standard_content: {
80+
query: keyword,
81+
minimum_should_match: "75%",
82+
boost: 2
83+
}
84+
}
8285
}
8386
],
8487
tie_breaker: 0.3

build.sh

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,47 @@ curl -H'Content-Type: application/json' -XPUT "http://localhost:9200/oiwiki" -d'
44
"settings": {
55
"analysis": {
66
"analyzer": {
7-
"default": {
7+
"pinyin_analyzer": {
88
"tokenizer": "ik_max_word",
9-
"filter": "custom_pinyin"
9+
"filter": "pinyin_filter"
1010
},
11-
"default_search": {
11+
"pinyin_search_analyzer": {
1212
"tokenizer": "ik_max_word"
1313
}
1414
},
1515
"filter": {
16-
"custom_pinyin": {
16+
"pinyin_filter": {
1717
"type": "pinyin",
1818
"keep_original": true,
19-
"limit_first_letter_length": 16
19+
"limit_first_letter_length": 16,
20+
"keep_joined_full_pinyin": true
2021
}
2122
}
2223
}
24+
},
25+
"mappings": {
26+
"properties": {
27+
"content": {
28+
"type": "text",
29+
"analyzer": "pinyin_analyzer",
30+
"search_analyzer": "pinyin_search_analyzer"
31+
},
32+
"h2": {
33+
"type": "text",
34+
"analyzer": "pinyin_analyzer",
35+
"search_analyzer": "pinyin_search_analyzer"
36+
},
37+
"title": {
38+
"type": "text",
39+
"analyzer": "pinyin_analyzer",
40+
"search_analyzer": "pinyin_search_analyzer"
41+
},
42+
"url": {
43+
"type": "text"
44+
},
45+
"standard_content": {
46+
"type": "text"
47+
}
48+
}
2349
}
2450
}'

webhook/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,18 @@ function updateContent(modified, removed) {
9090
const data = YAML.parse(file.replaceAll('!!python/name:', ''));
9191
let ops = [];
9292
modified.forEach((filename) => {
93-
ops.push({ index: { _index: 'oiwiki', _type: 'article', _id: filename } });
93+
ops.push({ index: { _index: 'oiwiki', _id: filename } });
9494
let [title, article, h2] = getContent(filename, data);
9595
ops.push({
9696
title: title,
9797
content: article,
9898
url: '/' + filename.replace('/index.md', '/').replace('.md', '/'),
9999
h2: h2,
100+
standard_content: article,
100101
});
101102
});
102103
removed.forEach((filename) => {
103-
ops.push({ delete: { _index: 'oiwiki', _type: 'article', _id: filename } });
104+
ops.push({ delete: { _index: 'oiwiki', _id: filename } });
104105
});
105106
client.bulk({ body: ops, refresh: 'true' }, function (err, res) {
106107
if (err) {

webhook/test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var client = new elasticsearch.Client({
66
let keyword = "线段";
77
const response = client.search({
88
index: "oiwiki",
9-
type: "article",
109
from: 0,
1110
size: 10,
1211
body: {
@@ -48,6 +47,15 @@ const response = client.search({
4847
boost: 3
4948
}
5049
}
50+
},
51+
{
52+
match: {
53+
standard_content: {
54+
query: keyword,
55+
minimum_should_match: "75%",
56+
boost: 2
57+
}
58+
}
5159
}
5260
],
5361
tie_breaker: 0.3

0 commit comments

Comments
 (0)