Hound 简介
Hound 是轻量级的快速代码搜索引擎。支持Git、SVN、Mercurial、Bazaar。Hound 自身是个静态 React 前端,可以和 Go 后端进行交互,后端拉取最新代码库并建立索引,并通过API进行代码搜索和页面展示。
效果如图
如何使用
- 安装Go
如果是MAC,并且安装过Homebrew , 可以直接执行 brew install go
即可安装。具体安装可以参考Go官网:Install Go
- 下载Hound源码包
git clone https://github.com/hound-search/hound.git
- 配置代码仓库地址
cd hound
hound 根目录下有一个default-config.json
文件,可以直接将它重命名成config.json , 然后在里面配置自己的代码仓库地址
mv default-config.json config.json
{
"dbpath" : "db",
"vcs-config" : {
"git": {
"ref" : "main"
}
},
"repos" : {
"Hound" : {
"url" : "https://github.com/hound-search/hound.git"
}
}
}
config-example.json
文件中有各个仓库的配置例子
具体配置的含义可以参考:hound config options
常用配置示例:只搜索指定分支
"Hound" : {
"url" : "https://github.com/hound-search/hound.git",
"url-pattern": {
"base-url": "https://github.com/hound-search/hound/blob/指定的分支名/{path}{anchor}"
}
}
- 启动 Hound
go run src/hound/cmds/houndd/main.go
正常情况下可以看到如下日志信息
2022/10/09 14:51:49 Searcher started for statsd
2022/10/09 14:51:49 Searcher started for Hound
2022/10/09 14:51:49 All indexes built!
2022/10/09 14:51:49 running server at http://localhost:6080
- 使用搜索
访问 http://localhost:6080/
即可体验快速的代码搜索,点击搜索结果文件会跳转到对应的代码仓库服务中的指定文件