예제 #1
0
/*****************************************************************************
*  function name : InitIndexSet
*  params : 需要初始化的字段
*  return :
*
*  description : 根据配置文件初始化建立索引和正排的字段并读入内存中
*
******************************************************************************/
func (this *IndexSet) InitIndexSet(fields map[string]string) error {

	for k, v := range fields {
		//this.Logger.Info(" KEY:%v  VALUE:%v\n",k,v)
		l := strings.Split(v, ",")
		if len(l) != 5 {
			this.Logger.Error("%v", errors.New("Wrong config file"))
			return errors.New("Wrong configure for index")
		}
		this.FieldInfo[k] = &IndexFieldInfo{false, false, false, "N", k, 0}
		stype, err := strconv.ParseInt(l[4], 0, 0)
		if err != nil {
			this.Logger.Error("Error to ParseInt[%v], %v", l[4], err)
			return err
		}

		this.FieldInfo[k].SType = stype

		if l[0] == "1" {
			this.PrimaryKey = k
			this.FieldInfo[k].IsPK = true
		}

		this.Logger.Info("========= Loading Index/Dictionary and Profile [ %v ] =========", k)
		if l[1] == "1" {
			this.FieldInfo[k].IsIvt = true
			idx := utils.NewInvertIdxWithName(k)
			this.Logger.Info("\t Loading Invert Index [ %v.idx.dic ] ", k)

			idx.ReadFromFile()
			if l[3] == "T" { //text ivt

				this.FieldInfo[k].FType = "T"
				dic := utils.NewStringIdxDic(k)
				this.Logger.Info("\t Loading Invert Index Dictionary [ %v.dic ] ", k)
				dic.ReadFromFile()

				index := NewTextIndex(k, idx, dic)
				this.PutIndex(k, index)

			} else { //number ivt

				this.FieldInfo[k].FType = "N"
				dic := utils.NewNumberIdxDic(k)
				this.Logger.Info("\t Loading Invert Index Dictionary [ %v.dic ] ", k)
				dic.ReadFromFile()
				dic.Display()
				index := NewNumberIndex(k, idx, dic)
				this.PutIndex(k, index)
			}

		}

		if l[2] == "1" {
			this.FieldInfo[k].IsPlf = true
			pfl_name := fmt.Sprintf("./index/%v_pfl.json", k)
			bpfl, _ := utils.ReadFromJson(pfl_name)

			if l[3] == "T" {
				this.FieldInfo[k].FType = "T"
				pfl := NewTextProfile(k)
				this.Logger.Info("\t Loading Text Profile [ %v.pfl ] ", k)
				pfl.ReadFromFile()

				this.PutProfile(k, pfl)

			} else if l[3] == "N" {
				this.FieldInfo[k].FType = "N"
				pfl := NewNumberProfile(k)
				this.Logger.Info("\t Loading Number Profile [ %v.pfl ] ", k)
				pfl.ReadFromFile()

				this.PutProfile(k, pfl)
			} else if l[3] == "I" {
				this.FieldInfo[k].FType = "I"
				var pfl ByteProfile
				this.Logger.Info("\t Loading Byte Profile [ %v.pfl ] ", pfl_name)
				err := json.Unmarshal(bpfl, &pfl)
				if err != nil {
					this.Logger.Error("Error to unmarshal[%v], %v", k, err)
					return err
				}
				this.PutProfile(k, &pfl)

			}
		}
	}

	//读取detail文件
	this.Logger.Info("Loading Detail idx .....")
	this.Detail = NewDetailWithFile()
	this.Detail.ReadDetailFromFile()
	/*
		bidx, err := utils.ReadFromJson("./index/detail.idx.json")
		if err != nil {
			this.Logger.Info("Read Detail Error .....%v ", err)
			return err
		}
		var detail Detail
		err = json.Unmarshal(bidx, &detail)
		if err != nil {
			this.Logger.Info("Loading Detail Error .....%v ", err)
			return err
		}
		this.Detail = &detail
	*/
	//保存最大DocId
	this.MaxDocId = this.PflIndex[this.PrimaryKey].GetMaxDocId()

	return nil
}
예제 #2
0
/*****************************************************************************
*  function name : InitIndexSet
*  params : 需要初始化的字段
*  return :
*
*  description : 根据配置文件初始化建立索引和正排的字段并读入内存中
*
******************************************************************************/
func (this *IndexSet) InitIndexSet(fields map[string]string, inc_field string) error {

	this.IncField = inc_field
	for k, v := range fields {

		var fi IndexFieldInfo
		err := json.Unmarshal([]byte(v), &fi)
		if err != nil {
			fmt.Printf("Unmarshal Error ...\n")
			return err
		}
		fi.Name = k
		this.FieldInfo[k] = &fi
		if this.FieldInfo[k].IsPK == true {
			this.PrimaryKey = k
		}
		cumstom := plugins.NewPlus(k)
		cumstom.Init()
		this.Logger.Info("========= Loading Index/Dictionary and Profile [ %v ] =========", k)
		if this.FieldInfo[k].IsIvt == true {
			idx := utils.NewInvertIdxWithName(k)
			this.Logger.Info("\t Loading Invert Index [ %v.idx.dic ] ", k)

			idx.ReadFromFile()
			if this.FieldInfo[k].FType == "T" || this.FieldInfo[k].FType == "I" { //text ivt

				dic := utils.NewStringIdxDic(k)
				this.Logger.Info("\t Loading Invert Index Dictionary [ %v.dic ] ", k)
				dic.ReadFromFile()

				index := NewTextIndex(k, idx, dic)
				index.SetCustomInterface(cumstom)
				this.PutIndex(k, index)

			} else if this.FieldInfo[k].FType == "N" { //number ivt

				dic := utils.NewNumberIdxDic(k)
				this.Logger.Info("\t Loading Invert Index Dictionary [ %v.dic ] ", k)
				dic.ReadFromFile()
				//dic.Display()
				index := NewNumberIndex(k, idx, dic)
				index.SetCustomInterface(cumstom)
				this.PutIndex(k, index)
			}

		}

		if this.FieldInfo[k].IsPlf == true {

			if this.FieldInfo[k].FType == "T" {

				pfl := NewTextProfile(k)
				this.Logger.Info("\t Loading Text Profile [ %v.pfl ] ", k)

				pfl.SetCustomInterface(cumstom)
				pfl.ReadFromFile()
				this.PutProfile(k, pfl)

			} else if this.FieldInfo[k].FType == "N" {

				pfl := NewNumberProfile(k)
				this.Logger.Info("\t Loading Number Profile [ %v.pfl ] ", k)

				pfl.SetCustomInterface(cumstom)
				pfl.ReadFromFile()

				this.PutProfile(k, pfl)
			} else if this.FieldInfo[k].FType == "I" {

				pfl := NewByteProfile(k)
				this.Logger.Info("\t Loading Byte Profile [ %v ] ", k)

				pfl.SetCustomInterface(cumstom)
				pfl.ReadFromFile()
				this.PutProfile(k, pfl)

			}
		}
	}

	//读取detail文件
	this.Logger.Info("Loading Detail idx .....")
	this.Detail = NewDetailWithFile()
	this.Detail.ReadDetailFromFile()
	//保存最大DocId
	this.MaxDocId = this.PflIndex[this.PrimaryKey].GetMaxDocId()

	return nil
}