예제 #1
0
// 根据配置文件进行初始化.
// 需要外部指定索引策略,策略可以重新设计.
// 需要外部知道被索引文件(这个易变信息不适合放配置)
func (this *GooseBuild) Init(confPath string, indexSty IndexStrategy, toIndexFile string) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = log.Error(r)
		}
	}()

	// load conf
	this.conf, err = config.NewConf(confPath)
	if err != nil {
		return
	}

	// set max procs
	maxProcs := int(this.conf.Int64("GooseBuild.MaxProcs"))
	if maxProcs <= 0 {
		maxProcs = runtime.NumCPU()
	}
	runtime.GOMAXPROCS(maxProcs)

	// init dbbuilder
	dbPath := this.conf.String("GooseBuild.DataBase.DbPath")
	transformMaxTermCnt := this.conf.Int64("GooseBuild.DataBase.TransformMaxTermCnt")
	maxId := this.conf.Int64("GooseBuild.DataBase.MaxId")
	maxIndexFileSize := this.conf.Int64("GooseBuild.DataBase.MaxIndexFileSize")
	maxDataFileSize := this.conf.Int64("GooseBuild.DataBase.MaxDataFileSize")
	valueSize := this.conf.Int64("GooseBuild.DataBase.ValueSize")

	this.staticDB = NewDBBuilder()
	err = this.staticDB.Init(dbPath, int(transformMaxTermCnt), InIdType(maxId),
		uint32(valueSize), uint32(maxIndexFileSize), uint32(maxDataFileSize))
	if err != nil {
		return
	}

	// index strategy global init
	err = indexSty.Init(this.conf)
	if err != nil {
		return
	}

	// static indexer
	this.staticIndexer, err = NewStaticIndexer(this.staticDB, indexSty)
	if err != nil {
		return
	}

	// open data file
	this.fileHd, err = os.OpenFile(toIndexFile, os.O_RDONLY, 0644)
	if err != nil {
		return
	}

	// file iter
	this.fileIter = NewFileIter(this.fileHd)

	return nil
}
예제 #2
0
파일: log.go 프로젝트: caohao2008/goose
func LoadConfiguration(confPath string) error {

	conf, err := config.NewConf(confPath)
	if err != nil {
		return err
	}

	var filt *log4go.FileLogWriter

	// debug
	debug_enable := conf.Bool("debug.Enable")
	debug_file := conf.String("debug.FileName")
	filt = nil
	if debug_enable {
		filt = newFileFilter(debug_file)
	}
	debugLogger["debug"] = &log4go.Filter{log4go.DEBUG, filt}

	// info
	info_enable := conf.Bool("info.Enable")
	info_file := conf.String("info.FileName")
	filt = nil
	if info_enable {
		filt = newFileFilter(info_file)
	}
	infoLogger["info"] = &log4go.Filter{log4go.INFO, filt}

	// error
	error_enable := conf.Bool("error.Enable")
	error_file := conf.String("error.FileName")
	filt = nil
	if error_enable {
		filt = newFileFilter(error_file)
	}
	errorLogger["error"] = &log4go.Filter{log4go.WARNING, filt}

	return nil
}
예제 #3
0
func (this *GooseSearch) Init(confPath string,
	indexSty IndexStrategy, searchSty SearchStrategy) (err error) {

	defer func() {
		if r := recover(); r != nil {
			err = log.Error(r)
		}
	}()

	// load conf
	this.conf, err = config.NewConf(confPath)
	if err != nil {
		return
	}

	// set max procs
	maxProcs := int(this.conf.Int64("GooseSearch.MaxProcs"))
	if maxProcs <= 0 {
		maxProcs = runtime.NumCPU()
	}
	runtime.GOMAXPROCS(maxProcs)
	log.Debug("set max procs [%d]", maxProcs)

	// init dbsearcher
	dbPath := this.conf.String("GooseBuild.DataBase.DbPath")
	log.Debug("init db [%s]", dbPath)

	this.searchDB = NewDBSearcher()
	err = this.searchDB.Init(dbPath)
	if err != nil {
		return
	}
	log.Debug("init db [%s]", dbPath)

	// index strategy global init
	if indexSty != nil {
		err = indexSty.Init(this.conf)
		if err != nil {
			return
		}
	}
	log.Debug("index strategy init finish")

	// search strategy global init
	if searchSty != nil {
		err = searchSty.Init(this.conf)
		if err != nil {
			return
		}
	}
	log.Debug("search strategy init finish")

	// var indexer
	if indexSty != nil {
		this.varIndexer, err = NewVarIndexer(this.searchDB, indexSty)
		if err != nil {
			return
		}
	}
	log.Debug("VarIndexer init finish")

	// searcher
	if searchSty != nil {
		this.searcher, err = NewSearcher(this.searchDB, searchSty)
		if err != nil {
			return
		}
	}
	log.Debug("Searcher init finish")

	return
}