sea-team / gofound

GoFound GoLang Full text search go语言全文检索引擎,毫秒级查询。 使用http接口调用,集成Admin管理界面,任何系统都可以使用。
Apache License 2.0
1.59k stars 190 forks source link

A golang SDK example without tcp #68

Open fy138 opened 1 year ago

fy138 commented 1 year ago
package main
import (
    "gofound/core"
    "gofound/global"
    "gofound/searcher/model"
    service2 "gofound/web/service"
    "log"
    "runtime"
)

type Services struct {
    Base     *service2.Base
    Index    *service2.Index
    Database *service2.Database
    Word     *service2.Word
}

func NewServices() *Services {
    return &Services{
        Base:     service2.NewBase(),
        Index:    service2.NewIndex(),
        Database: service2.NewDatabase(),
        Word:     service2.NewWord(),
    }
}

func main() {
    // Initialize 初始化
    //global.CONFIG = core.Parser() // if you need config.yaml
    global.CONFIG = &global.Config{
        //Addr:        *addr,
        Data:       "./data",
        Debug:      true,
        Dictionary: "./data/dictionary.txt",
        //EnableAdmin: false,
        Gomaxprocs: runtime.NumCPU(),
        //Auth:        "",
        //EnableGzip:  false,
        Timeout:   600,
        BufferNum: 1000,
    }
    //初始化分词器
    tokenizer := core.NewTokenizer(global.CONFIG.Dictionary)
    global.Container = core.NewContainer(tokenizer)

    srv := NewServices()

    log.Println(srv.Base.Status())

    request := &model.IndexDoc{}
    request.Id = 1
    request.Text = "下列关于静态代码块的描述中,正确的是(  )"
    t := `
            a. 使用静态代码块可以实现类的初始化
        b. 静态代码块随着类的加载而加载
        c. 每次创建对象时,类中的静态代码块都会被执行一次
        d. 静态代码块指的是被static关键字修饰的代码块
        `
    request.Document = map[string]interface{}{
        "content": t,
        "answer":  "静态代码块指的是被static关键字修饰的代码块, 静态代码块随着类的加载而加载, 使用静态代码块可以实现类的初始化",
    }
    log.Println(srv.Index.AddIndex("default", request))

}