Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A golang SDK example without tcp #68

Open
fy138 opened this issue Nov 18, 2022 · 0 comments
Open

A golang SDK example without tcp #68

fy138 opened this issue Nov 18, 2022 · 0 comments

Comments

@fy138
Copy link

fy138 commented Nov 18, 2022

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))

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant