Skip to content

Commit 1f6aede

Browse files
committed
feat(main.js): 默认使用前30个字符作为highlight
1 parent dca5f57 commit 1f6aede

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

api/main.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,16 @@ app.get('/', function(req, res) {
113113
results = results.hits.hits;
114114
results = results.map((e) => {
115115
let highlight = [];
116-
if(!e.highlight.content) highlight = e.highlight.h2;
117-
else if(!e.highlight.h2) highlight = e.highlight.content;
118-
else if(count(e.highlight.content[0]) >= count(e.highlight.h2[0])) highlight = e.highlight.content;
119-
else highlight = e.highlight.h2;
116+
if (!e.highlight.content && !e.highlight.h2) {
117+
highlight = [e._source.content.substring(0, 30)];
118+
} else if (e.highlight.content && e.highlight.h2) {
119+
const contentCount = count(e.highlight.content[0]);
120+
const h2Count = count(e.highlight.h2[0]);
121+
122+
highlight = (contentCount >= h2Count) ? e.highlight.content : e.highlight.h2;
123+
} else {
124+
highlight = e.highlight.content || e.highlight.h2;
125+
}
120126
return {
121127
url: e._source.url,
122128
title: e._source.title,

0 commit comments

Comments
 (0)