omochi
1.0.0
Golangʕ◔ϖ◔ʔ 從頭開始的全文搜尋引擎(只是玩具)
透過以下方式建立 docker 網路(omochi_network):
$ docker network create omochi_network
Omochi 使用 MariaDB 來儲存倒排索引和文檔,並使用 Ent 來儲存 ORM。
對於資料庫遷移,請透過以下方式連接 docker 容器 shell:
$ docker-compose run api bash
然後,透過以下方式運行資料庫遷移:
$ go run ./cmd/migrate/migrate.go
為了嘗試搜尋引擎,該專案提供了兩個 TSV 格式的資料集作為樣本。
英文的資料集是電影標題資料集,日文的資料集是哆啦A夢漫畫標題資料集。
首先,透過以下方式連接 docker 容器 shell:
$ docker-compose run api bash
然後,透過以下方式播種資料:
$ go run {path to seed.go}
如果使用日文資料集進行初始化, {path to seed.go}
應為./cmd/seeds/ja/seed.go
。另一方面,對於英語, ./cmd/seeds/eng/seed.go
。
完成設定後,您可以透過執行以下命令啟動應用程式:
$ docker-compose up
此應用程式啟動 RESTful API 並偵聽連接埠 8081 的連接
播種資料後,您可以透過向/v1/document/search
發送 GET 請求來搜尋文件。
查詢參數如下:
"keywords"
:要搜尋的關鍵字。如果有多個搜尋字詞,請指定它們並用逗號分隔,例如"hoge,fuga,piyo"
"mode"
:搜尋模式。可以指定的搜尋模式有"And"
和"Or"
透過哆啦A夢漫畫標題資料集播種後,可以透過以下方式搜尋包含「ドラえもん」的文件:
$ curl "http://localhost:8081/v1/document/search?keywords=ドラえもん" | jq .
{
"documents": [
{
"id": 12054,
"content": "ドラえもんの歌",
"tokenized_content": [
"ドラえもん",
"歌"
],
"created_at": "2022-07-08T12:59:49+09:00",
"updated_at": "2022-07-08T12:59:49+09:00"
},
{
"id": 11992,
"content": "恋するドラえもん",
"tokenized_content": [
"恋する",
"ドラえもん"
],
"created_at": "2022-07-08T12:59:48+09:00",
"updated_at": "2022-07-08T12:59:48+09:00"
},
{
"id": 11230,
"content": "ドラえもん登場!",
"tokenized_content": [
"ドラえもん",
"登場"
],
"created_at": "2022-07-08T12:59:44+09:00",
"updated_at": "2022-07-08T12:59:44+09:00"
},
...
透過電影標題資料集進行資料播種後,您可以透過以下方式搜尋包含「玩具」和「故事」的文檔:
$ curl "http://localhost:8081/v1/document/search?keywords=toy,story&mode=And" | jq .
{
"documents": [
{
"id": 1,
"content": "Toy Story",
"tokenized_content": [
"toy",
"story"
],
"created_at": "2022-07-08T13:49:24+09:00",
"updated_at": "2022-07-08T13:49:24+09:00"
},
{
"id": 39,
"content": "Toy Story of Terror!",
"tokenized_content": [
"toy",
"story",
"terror"
],
"created_at": "2022-07-08T13:49:34+09:00",
"updated_at": "2022-07-08T13:49:34+09:00"
},
{
"id": 83,
"content": "Toy Story That Time Forgot",
"tokenized_content": [
"toy",
"story",
"time",
"forgot"
],
"created_at": "2022-07-08T13:49:53+09:00",
"updated_at": "2022-07-08T13:49:53+09:00"
},
{
"id": 213,
"content": "Toy Story 2",
"tokenized_content": [
"toy",
"story"
],
"created_at": "2022-07-08T13:50:35+09:00",
"updated_at": "2022-07-08T13:50:35+09:00"
},
{
"id": 352,
"content": "Toy Story 3",
"tokenized_content": [
"toy",
"story"
],
"created_at": "2022-07-08T13:51:23+09:00",
"updated_at": "2022-07-08T13:51:23+09:00"
}
]
}
麻省理工學院