Riot Search分布式全文搜索引擎
riot 是一個(gè)分布式全文搜索引擎, 采用 Go 語(yǔ)言開(kāi)發(fā)。
功能特性:
-
高效索引和搜索(1M 條微博 500M 數(shù)據(jù)28秒索引完,1.65毫秒搜索響應(yīng)時(shí)間,19K 搜索 QPS)
-
支持中文分詞(使用 gse 分詞包并發(fā)分詞,速度 27MB/秒)
-
支持邏輯搜索
-
支持中文轉(zhuǎn)拼音搜索(使用 gpy 中文轉(zhuǎn)拼音)
-
支持計(jì)算關(guān)鍵詞在文本中的緊鄰距離(token proximity)
-
支持計(jì)算BM25相關(guān)度
-
支持自定義評(píng)分字段和評(píng)分規(guī)則
-
支持在線添加、刪除索引
-
支持多種持久存儲(chǔ)
-
支持 heartbeat
-
支持分布式索引和搜索
-
可實(shí)現(xiàn)分布式索引和搜索
-
采用對(duì)商業(yè)應(yīng)用友好的Apache License v2發(fā)布
-
支持分詞規(guī)則
安裝/更新
go get -u github.com/go-ego/riot
Requirements
需要 Go 版本至少 1.8
Dependencies
Riot 使用 go module 或 dep 管理依賴.
Build-tools
go get -u github.com/go-ego/re
re riot
創(chuàng)建 riot 項(xiàng)目
$ re riot my-riotapp
re run
運(yùn)行我們創(chuàng)建的 riot 項(xiàng)目, 你可以導(dǎo)航到應(yīng)用程序文件夾并執(zhí)行:
$ cd my-riotapp && re run
使用
先看一個(gè)例子(來(lái)自 simplest_example.go)
package main
import (
"log"
"github.com/go-ego/riot"
"github.com/go-ego/riot/types"
)
var (
// searcher 是協(xié)程安全的
searcher = riot.Engine{}
)
func main() {
// 初始化
searcher.Init(types.EngineOpts{
Using: 3,
GseDict: "zh",
// GseDict: "your gopath"+"/src/github.com/go-ego/riot/data/dict/dictionary.txt",
})
defer searcher.Close()
text := "《復(fù)仇者聯(lián)盟3:無(wú)限戰(zhàn)爭(zhēng)》是全片使用IMAX攝影機(jī)拍攝"
text1 := "在IMAX影院放映時(shí)"
text2 := "全片以上下擴(kuò)展至IMAX 1.9:1的寬高比來(lái)呈現(xiàn)"
// 將文檔加入索引,docId 從1開(kāi)始
searcher.Index("1", types.DocData{Content: text})
searcher.Index("2", types.DocData{Content: text1}, false)
searcher.Index("3", types.DocData{Content: text2}, true)
// 等待索引刷新完畢
searcher.Flush()
// engine.FlushIndex()
// 搜索輸出格式見(jiàn) types.SearchResp 結(jié)構(gòu)體
log.Print(searcher.Search(types.SearchReq{Text:"復(fù)仇者"}))
}
是不是很簡(jiǎn)單!
然后看看一個(gè)入門(mén)教程,教你用不到200行 Go 代碼實(shí)現(xiàn)一個(gè)微博搜索網(wǎng)站。
使用默認(rèn)引擎:
package main
import (
"log"
"github.com/go-ego/riot"
"github.com/go-ego/riot/types"
)
var (
searcher = riot.New("zh")
)
func main() {
data := types.DocData{Content: `I wonder how, I wonder why
, I wonder where they are`}
data1 := types.DocData{Content: "所以, 你好, 再見(jiàn)"}
data2 := types.DocData{Content: "沒(méi)有理由"}
searcher.Index("1", data)
searcher.Index("2", data1)
searcher.IndexDoc("3", data2)
searcher.Flush()
req := types.SearchReq{Text: "你好"}
search := searcher.Search(req)
log.Println("search...", search)
}評(píng)論
圖片
表情
