Esempio n. 1
0
// addDocument function description : 增加一个doc文档
// params : docid docid的编号
//			contentstr string  文档内容
// return : error 成功返回Nil,否则返回相应的错误信息
func (this *profile) addDocument(docid uint32, content interface{}) error {

	if docid != this.curDocId || this.isMomery == false {
		return errors.New("profile --> AddDocument :: Wrong DocId Number")
	}
	this.Logger.Trace("[TRACE] docid %v content %v", docid, content)

	vtype := reflect.TypeOf(content)
	var value int64 = 0xFFFFFFFF
	var ok error
	switch vtype.Name() {
	case "int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64":

		value, ok = strconv.ParseInt(fmt.Sprintf("%v", content), 0, 0)
		if ok != nil {
			value = 0xFFFFFFFF
		}
		this.pflNumber = append(this.pflNumber, value)
	case "float32":
		v, _ := content.(float32)
		value = int64(v * 100)
		this.pflNumber = append(this.pflNumber, value)
	case "float64":
		v, _ := content.(float64)
		value = int64(v * 100)
		this.pflNumber = append(this.pflNumber, value)
	case "string":
		if this.fieldType == utils.IDX_TYPE_NUMBER {
			value, ok = strconv.ParseInt(fmt.Sprintf("%v", content), 0, 0)
			if ok != nil {
				value = 0xFFFFFFFF
			}
			//this.Logger.Info("[INFO] value %v", value)
			this.pflNumber = append(this.pflNumber, value)
			//this.pflString = append(this.pflString, fmt.Sprintf("%v", content))
		} else if this.fieldType == utils.IDX_TYPE_DATE {

			value, _ = utils.IsDateTime(fmt.Sprintf("%v", content))
			this.pflNumber = append(this.pflNumber, value)

		} else {
			this.pflString = append(this.pflString, fmt.Sprintf("%v", content))
		}
	default:
		this.pflString = append(this.pflString, fmt.Sprintf("%v", content))
	}
	this.curDocId++
	return nil
}
Esempio n. 2
0
func (this *profile) updateDocument(docid uint32, content interface{}) error {

	if this.fieldType != utils.IDX_TYPE_NUMBER || this.fieldType != utils.IDX_TYPE_DATE {
		return errors.New("not support")
	}

	vtype := reflect.TypeOf(content)
	var value int64 = 0xFFFFFFFF
	switch vtype.Name() {
	case "string", "int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64":
		var ok error
		if this.fieldType == utils.IDX_TYPE_DATE {
			value, _ = utils.IsDateTime(fmt.Sprintf("%v", content))
		}
		value, ok = strconv.ParseInt(fmt.Sprintf("%v", content), 0, 0)
		if ok != nil {
			value = 0xFFFFFFFF
		}

	case "float32":
		v, _ := content.(float32)
		value = int64(v * 100)
	case "float64":
		v, _ := content.(float64)
		value = int64(v * 100)
	default:
		value = 0xFFFFFFFF
	}
	if this.isMomery == true {
		this.pflNumber[docid-this.startDocId] = value
	} else {
		offset := this.pflOffset + int64((docid-this.startDocId)*8)
		this.pflMmap.WriteInt64(offset, value)
	}
	return nil
}