gofound 试用

2023-09-06 19:24:19 浏览数 (1)

https://github.com/sea-team/gofound是纯go实现的一个类es的简易版本搜索引擎。支持全文检索引擎 基于平衡二叉树 正排索引、倒排索引实现 可支持亿级数据,毫秒级查询。使用简单,使用http接口。

安装

代码语言:javascript复制
go get && go build

启动

代码语言:javascript复制
% ./gofound --addr=:8080 --data=./data
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /admin/                   --> github.com/sea-team/gofound/web/admin.adminIndex (4 handlers)
[GIN-debug] GET    /assets/*filepath         --> github.com/sea-team/gofound/web/admin.handlerStatic (4 handlers)
2023/04/15 21:53:47 Admin Url:   http://:8080/admin
[GIN-debug] GET    /api/                     --> github.com/sea-team/gofound/web/controller.Welcome (6 handlers)
[GIN-debug] POST   /api/query                --> github.com/sea-team/gofound/web/controller.Query (6 handlers)
[GIN-debug] GET    /api/status               --> github.com/sea-team/gofound/web/controller.Status (6 handlers)
[GIN-debug] GET    /api/gc                   --> github.com/sea-team/gofound/web/controller.GC (6 handlers)
[GIN-debug] POST   /api/index                --> github.com/sea-team/gofound/web/controller.AddIndex (6 handlers)
[GIN-debug] POST   /api/index/batch          --> github.com/sea-team/gofound/web/controller.BatchAddIndex (6 handlers)
[GIN-debug] POST   /api/index/remove         --> github.com/sea-team/gofound/web/controller.RemoveIndex (6 handlers)
[GIN-debug] GET    /api/db/list              --> github.com/sea-team/gofound/web/controller.DBS (6 handlers)
[GIN-debug] GET    /api/db/drop              --> github.com/sea-team/gofound/web/controller.DatabaseDrop (6 handlers)
[GIN-debug] GET    /api/db/create            --> github.com/sea-team/gofound/web/controller.DatabaseCreate (6 handlers)
[GIN-debug] GET    /api/word/cut             --> github.com/sea-team/gofound/web/controller.WordCut (6 handlers)
2023/04/15 21:53:47 API Url:     http://:8080/api

查看admin后台

代码语言:javascript复制
http://127.0.0.1:8080/admin/#/

查看api接口

代码语言:javascript复制
http://127.0.0.1:8080/api/
{
state: true,
message: "success",
data: "Welcome to GoFound"
}

gofound启动之后,会监听一个TCP端口,接收来自客户端的搜索请求。处理http请求部分使用gin框架。如果不指定,默认数据库为default。

插入数据

代码语言:javascript复制
 % curl -H "Content-Type:application/json" -X POST --data '{"id":88888,"text":"深圳北站","document":{"title":"阿森松岛所445","number":223}}' 'http://127.0.0.1:8080/api/index?database=default'
{"state":true,"message":"success"}

批量插入

代码语言:javascript复制
curl -H "Content-Type:application/json" -X POST --data '[
  {
    "id": 88888,
    "text": "深圳北站",
    "document": {
      "title": "阿森松岛所445",
      "number": 223
    }
  },
  {
    "id": 22222,
    "text": "北京东站",
    "document": {
      "title": "123123123",
      "number": 123123
    }
  }
]' 'http://127.0.0.1:8080/api/index/batch?database=default'

{"state":true,"message":"success"}

查询状态

代码语言:javascript复制
% curl http://127.0.0.1:8080/api/status
{"state":true,"message":"success","data":{"cpu":{"cores":4,"usedPercent":9.43,"modelName":"Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz"},"disk":{"total":233.57,"used":216.64,"free":16.93,"fsType":"apfs","usedPercent":92.75,"path":"/"},"memory":{"total":8,"used":5.62,"free":0.14,"self":0.05,"usedPercent":70.28},"system":{"arch":"amd64","bufferNum":1000,"cores":4,"dataPath":"./data","dataSize":8.25,"dbs":1,"debug":true,"dictionaryPath":"./data/dictionary.txt","enableAuth":false,"enableGzip":true,"executable":"./gofound","gomaxprocs":8,"goroutines":53,"os":"darwin","pid":54603,"shard":0,"version":"go1.19"}}
代码语言:javascript复制
% curl http://127.0.0.1:8080/api/db/list
{"state":true,"message":"success","data":{"default":{"IndexPath":"./data/default","Option":{"InvertedIndexName":"inverted_index","PositiveIndexName":"positive_index","DocIndexName":"docs"},"IsDebug":true,"Tokenizer":{},"DatabaseName":"default","Shard":10,"Timeout":600,"BufferNum":1000}}}

查询

代码语言:javascript复制
 %  curl -H "Content-Type:application/json" -X POST --data '{"query":"深圳北站","page":1,"limit":10,"order":"desc"}' http://127.0.0.1:8080/api/query
{"state":true,"message":"success","data":{"time":107.278619,"total":1,"pageCount":1,"page":1,"limit":10,"documents":[{"id":88888,"text":"深圳北站","document":{"number":223,"title":"阿森松岛所445"},"score":2,"keys":["深圳","北站"]}],"words":["深圳","北站"]}}

分词

代码语言:javascript复制
% curl 'http://127.0.0.1:8080/api/word/cut?q=上海和深圳哪个城市幸福指数高'
{"state":true,"message":"success","data":["上海","和","深圳","哪个","城市","幸福","指数","高"]}

0 人点赞