Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit 440f638

Browse files
committed
重构:更新搜索服务配置和错误处理
- 将 `debug` 常量更改为 `false` - 在启动搜索服务之前,添加对 `bert.bin` 和 `bert-tokenizer.json` 存在性的检查 - 如果 `bert.bin` 或 `bert-tokenizer.json` 不存在,则打印日志消息 - 如果搜索功能未开启,则返回消息
1 parent 00bd40a commit 440f638

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var fsbin embed.FS
3030

3131
var lm NLP
3232

33-
const debug = true
33+
const debug = false
3434

3535
const PORT = "36182" //内部端口
3636

search.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package main
22

33
import (
4+
"log"
5+
46
"github.com/wailovet/gosearch"
7+
"github.com/wailovet/nuwa"
58
)
69

710
var msearch *gosearch.BingSearch
811
var segBlock = gosearch.DefaultSegBlock
912

1013
func searchServiceStartUp() {
14+
if !nuwa.Helper().PathExists("bert.bin") || !nuwa.Helper().PathExists("bert-tokenizer.json") {
15+
log.Println("bert.bin or bert-tokenizer.json not exists")
16+
return
17+
}
1118
gosearch.Install(
1219
"bert.bin",
1320
"bert-tokenizer.json",
@@ -18,6 +25,9 @@ func searchServiceStartUp() {
1825
}
1926

2027
func search(query string, blockQuery string, day ...int) string {
28+
if msearch == nil {
29+
return "Search function is not turned on"
30+
}
2131
threshold := float32(3)
2232
text := msearch.Search(query, threshold, 5, day...)
2333
if text == "" && len(day) > 0 && day[0] == 0 {

0 commit comments

Comments
 (0)