Riot Search分布式全文搜索引擎

联合创作 · 2023-09-29 03:26

riot 是一个分布式全文搜索引擎, 采用 Go 语言开发。


功能特性:



  • 高效索引和搜索(1M 条微博 500M 数据28秒索引完,1.65毫秒搜索响应时间,19K 搜索 QPS)


  • 支持中文分词(使用 gse 分词包并发分词,速度 27MB/秒)


  • 支持逻辑搜索


  • 支持中文转拼音搜索(使用 gpy 中文转拼音)


  • 支持计算关键词在文本中的紧邻距离(token proximity)


  • 支持计算BM25相关度


  • 支持自定义评分字段和评分规则


  • 支持在线添加、删除索引


  • 支持多种持久存储


  • 支持 heartbeat


  • 支持分布式索引和搜索


  • 可实现分布式索引和搜索


  • 采用对商业应用友好的Apache License v2发布


  • 支持分词规则



安装/更新



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


创建 riot 项目



$ re riot my-riotapp

re run


运行我们创建的 riot 项目, 你可以导航到应用程序文件夹并执行:



$ cd my-riotapp && re run

使用


先看一个例子(来自 simplest_example.go



package main

import (
"log"

"github.com/go-ego/riot"
"github.com/go-ego/riot/types"
)

var (
// searcher 是协程安全的
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 := "《复仇者联盟3:无限战争》是全片使用IMAX摄影机拍摄"
text1 := "在IMAX影院放映时"
text2 := "全片以上下扩展至IMAX 1.9:1的宽高比来呈现"

// 将文档加入索引,docId 从1开始
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()

// 搜索输出格式见 types.SearchResp 结构体
log.Print(searcher.Search(types.SearchReq{Text:"复仇者"}))
}

是不是很简单!


然后看看一个入门教程,教你用不到200行 Go 代码实现一个微博搜索网站。


使用默认引擎:



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: "所以, 你好, 再见"}
data2 := types.DocData{Content: "没有理由"}

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)
}
浏览 29
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报