riot
packagemoduleThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
Riot search
Go Open Source, Distributed, Simple and efficient full text search engine.
Features
Efficient indexing and search (1M blog 500M data 28 seconds index finished, 1.65 ms search response time, 19K search QPS)
Support forlogical search
Support Chinese word segmentation (usegse word segmentation package concurrent word, speed 27MB / s)
Support the calculation of the keyword in the textclose to the distance(token proximity)
Support calculationBM25 correlation
Supportadd online, delete index
Support heartbeat
Support multiplepersistent storage
Supportdistributed index and search
Can be achieveddistributed index and search
Requirements
Go version >= 1.8
Dependencies
Riot uses go module or dep to manage dependencies.
Installation/Update
go get -u github.com/go-ego/riot
Build-tools
go get -u github.com/go-ego/re
re riot
To create a new riot application
$ re riot my-riotapp
re run
To run the application we just created, you can navigate to the application folder and execute:
$ cd my-riotapp && re run
Usage:
Look at an example
package mainimport ("log""github.com/go-ego/riot""github.com/go-ego/riot/types")var (// searcher is coroutine safesearcher = riot.Engine{})func main() {// Initsearcher.Init(types.EngineOpts{// Using: 4,NotUseGse: true,})defer searcher.Close()text := "Google Is Experimenting With Virtual Reality Advertising"text1 := `Google accidentally pushed Bluetooth update for Homespeaker early`text2 := `Google is testing another Search results layout with rounded cards, new colors, and the 4 mysterious colored dots again`// Add the document to the index, docId starts at 1searcher.Index("1", types.DocData{Content: text})searcher.Index("2", types.DocData{Content: text1}, false)searcher.IndexDoc("3", types.DocData{Content: text2}, true)// Wait for the index to refreshsearcher.Flush()// engine.FlushIndex()// The search output format is found in the types.SearchResp structurelog.Print(searcher.Search(types.SearchReq{Text:"google testing"}))}
It is very simple!
Use default engine:
package mainimport ("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.Index("3", data2)searcher.Flush()req := types.SearchReq{Text: "你好"}search := searcher.Search(req)log.Println("search...", search)}
Look at more Examples
Look at Store example
Look at Logic search example
Look at Pinyin search example
Look at different dict and language search example
Look at benchmark example
Riot search engine templates, client and dictionaries
Authors
License
Riot is primarily distributed under the terms of the Apache License (Version 2.0), base onwukong.
Documentation¶
Overview¶
Package riot is riot engine
Package riot full text search engine
Index¶
- Constants
- Variables
- func AddDocs(engine *Engine)
- func AddDocsWithLabels(engine *Engine)
- func CPUInfo(args ...int) (string, error)
- func CPUPercent() ([]float64, error)
- func DiskFree() (uint64, error)
- func DiskPercent() (string, error)
- func DiskTotal() (uint64, error)
- func DiskUsed() (uint64, error)
- func GetVersion() string
- func KernelVer() (string, error)
- func MemFree() (uint64, error)
- func MemPercent() (string, error)
- func MemTotal() (uint64, error)
- func MemUsed() (uint64, error)
- func OrderlessOpts(idOnly bool) types.EngineOpts
- func Platform() (string, error)
- func PlatformInfo() (platform, family, osVersion string, err error)
- func ToGB(data uint64) uint64
- func ToKB(data uint64) uint64
- func ToMB(data uint64) uint64
- func Try(fun func(), handler func(interface{}))
- func Uptime() (uptime uint64, err error)
- type Engine
- func (engine *Engine) CheckMem()
- func (engine *Engine) Close()
- func (engine *Engine) Flush()
- func (engine *Engine) FlushIndex()
- func (engine *Engine) ForSplitData(strData []string, num int) (TMap, int)
- func (engine *Engine) GetAllDocIds() []string
- func (engine *Engine) GetDBAllDocs() (docsId []string, docsData []types.DocData)
- func (engine *Engine) GetDBAllIds() []string
- func (engine *Engine) HasDoc(docId string) bool
- func (engine *Engine) HasDocDB(docId string) bool
- func (engine *Engine) Index(docId string, data types.DocData, forceUpdate ...bool)
- func (engine *Engine) IndexDoc(docId string, data types.DocData, forceUpdate ...bool)
- func (engine *Engine) Indexer(options types.EngineOpts)
- func (engine *Engine) Init(options types.EngineOpts)
- func (engine *Engine) InitStore()
- func (engine *Engine) NotTimeOut(request types.SearchReq, rankerReturnChan chan rankerReturnReq) (rankOutArr interface{}, numDocs int)
- func (engine *Engine) NumDocsIndexed() uint64
- func (engine *Engine) NumDocsRemoved() uint64
- func (engine *Engine) NumIndexed() uint64
- func (engine *Engine) NumRemoved() uint64
- func (engine *Engine) NumTokenAdded() uint64
- func (engine *Engine) NumTokenIndexAdded() uint64
- func (engine *Engine) PinYin(hans string) []string
- func (engine *Engine) RankID(request types.SearchReq, rankOpts types.RankOpts, tokens []string, ...) (output types.SearchResp)
- func (engine *Engine) Ranker(options types.EngineOpts)
- func (engine *Engine) Ranks(request types.SearchReq, rankOpts types.RankOpts, tokens []string, ...) (output types.SearchResp)
- func (engine *Engine) RemoveDoc(docId string, forceUpdate ...bool)
- func (engine *Engine) Search(request types.SearchReq) (output types.SearchResp)
- func (engine *Engine) SearchDoc(request types.SearchReq) (output types.SearchDoc)
- func (engine *Engine) SearchID(request types.SearchReq) (output types.SearchID)
- func (engine *Engine) Segment(content string) (keywords []string)
- func (engine *Engine) Store()
- func (engine *Engine) TimeOut(request types.SearchReq, rankerReturnChan chan rankerReturnReq) (rankOutArr interface{}, numDocs int, isTimeout bool)
- func (engine *Engine) Tokens(request types.SearchReq) (tokens []string)
- func (engine *Engine) UsedDisk() (uint64, error)
- func (engine *Engine) UsedMem() (uint64, error)
- func (engine *Engine) WithGse(segmenter gse.Segmenter) *Engine
- type RankByTokenProximity
- type ScoringFields
- type StopTokens
- type TMap
Constants¶
const (// Version get the riot versionVersionstring = "v0.10.0.425, Danube River!"// NumNanosecondsInAMillisecond nano-seconds in a milli-second numNumNanosecondsInAMillisecond = 1000000// StoreFilePrefix persistent store file prefixStoreFilePrefix = "riot"// DefaultPath default db pathDefaultPath = "./riot-index")
Variables¶
var (// InitMemUsed init mem usedInitMemUseduint64// InitDiskUsed init disk usedInitDiskUseduint64)
var (Req1 =types.SearchReq{Text: reqText})
var (TestIndexOpts = rankEngineOpts(rankOptsMax10))
Functions¶
funcAddDocsWithLabels¶
func AddDocsWithLabels(engine *Engine)
funcCPUPercent¶
CPUPercent returns the amount of use cpu in percent.
funcDiskPercent¶
DiskPercent returns the amount of use disk in percent.
funcMemPercent¶
MemPercent returns the amount of use memory in percent.
funcOrderlessOpts¶
func OrderlessOpts(idOnlybool)types.EngineOpts
funcPlatformInfo¶
PlatformInfo fetches system platform information.
Types¶
typeEngine¶
type Engine struct {// contains filtered or unexported fields}
Engine initialize the engine
func (*Engine)CheckMem¶
func (engine *Engine) CheckMem()
CheckMem check the memory when the memory is largerthan 99.99% using the store
func (*Engine)Flush¶
func (engine *Engine) Flush()
Flush block wait until all indexes are added阻塞等待直到所有索引添加完毕
func (*Engine)FlushIndex¶
func (engine *Engine) FlushIndex()
FlushIndex block wait until all indexes are added阻塞等待直到所有索引添加完毕
func (*Engine)ForSplitData¶
ForSplitData for split segment's data, segspl
func (*Engine)GetAllDocIds¶
GetAllDocIds get all the DocId from the storage databaseand return从数据库遍历所有的 DocId, 并返回
func (*Engine)GetDBAllDocs¶
GetDBAllDocs get the db all docs
func (*Engine)GetDBAllIds¶
GetDBAllIds get all the DocId from the storage databaseand return从数据库遍历所有的 DocId, 并返回
func (*Engine)IndexDoc¶
IndexDoc add the document to the index将文档加入索引
输入参数:
docId 标识文档编号,必须唯一,docId == 0 表示非法文档(用于强制刷新索引),[1, +oo) 表示合法文档data 见 DocIndexData 注释forceUpdate 是否强制刷新 cache,如果设为 true,则尽快添加到索引,否则等待 cache 满之后一次全量添加
注意:
- 这个函数是线程安全的,请尽可能并发调用以提高索引速度
- 这个函数调用是非同步的,也就是说在函数返回时有可能文档还没有加入索引中,因此如果立刻调用Search可能无法查询到这个文档。强制刷新索引请调用FlushIndex函数。
func (*Engine)Indexer¶
func (engine *Engine) Indexer(optionstypes.EngineOpts)
Indexer initialize the indexer channel
func (*Engine)InitStore¶
func (engine *Engine) InitStore()
InitStore initialize the persistent store channel
func (*Engine)NotTimeOut¶
func (engine *Engine) NotTimeOut(requesttypes.SearchReq,rankerReturnChan chan rankerReturnReq) (rankOutArr interface{}, numDocsint)
NotTimeOut not set engine timeout
func (*Engine)NumDocsIndexed¶
NumDocsIndexed documents indexed number, deprecated
func (*Engine)NumDocsRemoved¶
NumDocsRemoved documents removed number, deprecated
func (*Engine)NumIndexed¶
NumIndexed documents indexed number
func (*Engine)NumRemoved¶
NumRemoved documents removed number
func (*Engine)NumTokenAdded¶
NumTokenAdded added token index number
func (*Engine)NumTokenIndexAdded¶
NumTokenIndexAdded added token index number, deprecated
func (*Engine)RankID¶
func (engine *Engine) RankID(requesttypes.SearchReq, rankOptstypes.RankOpts,tokens []string, rankerReturnChan chan rankerReturnReq) (outputtypes.SearchResp)
RankID rank docs by types.ScoredIDs
func (*Engine)Ranker¶
func (engine *Engine) Ranker(optionstypes.EngineOpts)
Ranker initialize the ranker channel
func (*Engine)Ranks¶
func (engine *Engine) Ranks(requesttypes.SearchReq, rankOptstypes.RankOpts,tokens []string, rankerReturnChan chan rankerReturnReq) (outputtypes.SearchResp)
Ranks rank docs by types.ScoredDocs
func (*Engine)RemoveDoc¶
RemoveDoc remove the document from the index将文档从索引中删除
输入参数:
docId 标识文档编号,必须唯一,docId == 0 表示非法文档(用于强制刷新索引),[1, +oo) 表示合法文档forceUpdate 是否强制刷新 cache,如果设为 true,则尽快删除索引,否则等待 cache 满之后一次全量删除
注意:
- 这个函数是线程安全的,请尽可能并发调用以提高索引速度
- 这个函数调用是非同步的,也就是说在函数返回时有可能文档还没有加入索引中,因此如果立刻调用 Search 可能无法查询到这个文档。强制刷新索引请调用 FlushIndex 函数。
func (*Engine)Search¶
func (engine *Engine) Search(requesttypes.SearchReq) (outputtypes.SearchResp)
Search find the document that satisfies the search criteria.This function is thread safe查找满足搜索条件的文档,此函数线程安全
func (*Engine)SearchDoc¶
SearchDoc find the document that satisfies the search criteria.This function is thread safe, return not IDonly
func (*Engine)SearchID¶
SearchID find the document that satisfies the search criteria.This function is thread safe, return IDonly
func (*Engine)TimeOut¶
func (engine *Engine) TimeOut(requesttypes.SearchReq,rankerReturnChan chan rankerReturnReq) (rankOutArr interface{}, numDocsint, isTimeoutbool)
TimeOut set engine timeout
typeRankByTokenProximity¶
type RankByTokenProximity struct {}
func (RankByTokenProximity)Score¶
func (ruleRankByTokenProximity) Score(doctypes.IndexedDoc, fields interface{}) []float32
typeScoringFields¶
type ScoringFields struct {A, B, Cfloat32}
typeStopTokens¶
type StopTokens struct {// contains filtered or unexported fields}
StopTokens stop tokens map
func (*StopTokens)Init¶
func (st *StopTokens) Init(stopTokenFilestring)
Init 从 stopTokenFile 中读入停用词,一个词一行文档索引建立时会跳过这些停用词
func (*StopTokens)IsStopToken¶
func (st *StopTokens) IsStopToken(tokenstring)bool
IsStopToken to determine whether to stop token
Source Files¶
Directories¶
Path | Synopsis |
---|---|
Package core is riot core | Package core is riot core |
Package engine is riot engine | Package engine is riot engine |
examples | |
benchmark riot 性能测试 | riot 性能测试 |
codelab 一个微博搜索的例子。 | 一个微博搜索的例子。 |
pinyin_weibo 一个微博 pinyin 搜索的例子。 | 一个微博 pinyin 搜索的例子。 |
Package net is riot net | Package net is riot net |
Package types is riot types | Package types is riot types |