gofound 試用

        https://github.com/sea-team/gofound 是純 go 實現的一個類 es 的簡易版本搜索引擎。支持全文檢索引擎 基於平衡二叉樹 + 正排索引、倒排索引實現 可支持億級數據,毫秒級查詢。使用簡單,使用 http 接口。

        安裝

go get && go build

  啓動

% ./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 後臺

http://127.0.0.1:8080/admin/#/

查看 api 接口

http://127.0.0.1:8080/api/
{
state: true,
message: "success",
data: "Welcome to GoFound"
}

        gofound 啓動之後,會監聽一個 TCP 端口,接收來自客戶端的搜索請求。處理 http 請求部分使用 gin 框架。如果不指定,默認數據庫爲 default。

    插入數據

 % 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"}

批量插入

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"}

查詢狀態

% 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"}}
% 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}}}

查詢

 %  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":["深圳","北站"]}}

分詞

% curl 'http://127.0.0.1:8080/api/word/cut?q=上海和深圳哪個城市幸福指數高'
{"state":true,"message":"success","data":["上海","和","深圳","哪個","城市","幸福","指數","高"]}
本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s/LT9T_KFz5sW8K3nPXa9e9w