forked from MACDfree/asearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (65 loc) · 2.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"asearch/config"
"asearch/logger"
"asearch/notification"
"asearch/searchengine"
"asearch/webserver"
"os"
"github.com/blevesearch/bleve/v2"
"github.com/pkg/errors"
"github.com/skratchdot/open-golang/open"
)
func main() {
logger.Info("asearch开始执行")
logger.Info("判断索引文件是否存在")
_, err := os.Stat(config.Conf.IndexPath)
if err != nil {
logger.Infof("索引文件%s不存在", config.Conf.IndexPath)
logger.Info("判断数据文件是否存在")
_, err = os.Stat(config.Conf.DBPath)
if err != nil {
logger.Infof("数据文件%s不存在", config.Conf.DBPath)
} else {
logger.Infof("数据文件%s存在", config.Conf.DBPath)
logger.Info("删除数据文件")
os.RemoveAll(config.Conf.DBPath)
}
logger.Info("开始创建索引")
searchengine.BuildIndex(config.Conf.IndexPath)
logger.Info("结束创建索引,建议重新启动程序,以释放资源")
} else {
logger.Infof("索引文件%s存在", config.Conf.IndexPath)
logger.Info("判断数据文件是否存在")
_, err = os.Stat(config.Conf.DBPath)
if err != nil {
logger.Infof("数据文件%s不存在", config.Conf.DBPath)
logger.Info("删除索引文件")
os.RemoveAll(config.Conf.IndexPath)
logger.Info("开始创建索引")
searchengine.BuildIndex(config.Conf.IndexPath)
logger.Info("结束创建索引,建议重新启动程序,以释放资源")
} else {
logger.Infof("数据文件%s存在", config.Conf.DBPath)
}
}
logger.Info("打开索引文件")
index, err := bleve.Open(config.Conf.IndexPath)
if err != nil {
panic(err)
}
logger.Info("执行一次索引更新操作")
searchengine.ReBuildIndex(index)
logger.Info("开始更新索引定时任务")
searchengine.StartRebuildJob(index)
logger.Info("准备提供搜索服务")
go webserver.Run(config.Conf.Addr, index)
if config.Conf.OpenBrowserOnStart {
logger.Info("自动打开本地浏览器")
err := open.Start("http://" + config.Conf.Addr)
if err != nil {
logger.Error(errors.Cause(err))
}
}
notification.Run()
}