go-ego / riot

Go Open Source, Distributed, Simple and efficient Search Engine; Warning: This is V1 and beta version, because of big memory consume, and the V2 will be rewrite all code.
Apache License 2.0
6.11k stars 474 forks source link

Is it possible to search short sentences with long sentences #107

Open oldfeel opened 4 years ago

oldfeel commented 4 years ago
package main

import (
    "log"

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

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影复仇院放映时者"

    // 将文档加入索引,docId 从1开始
    searcher.Index("你好,世界", types.DocData{Content: text})
    searcher.Index("2", types.DocData{Content: text1}, false)

    // 等待索引刷新完毕
    searcher.Flush()
    // engine.FlushIndex()

    // 搜索输出格式见 types.SearchResp 结构体
    log.Print(ofutils.ToJson(searcher.Search(types.SearchReq{Text: "复仇者大联盟"})))
    log.Print(ofutils.ToJson(searcher.Search(types.SearchReq{Text: "《复仇者联盟3:无限战争》是全片使用IMAX摄影机拍摄"})))
}

Description

I want to use Big Avengers to search for Avengers, can it? ...