Example #1
0
// SearchUnitDocIds function description : 搜索的基本单元
// params :
// return :
func (this *Segment) SearchUnitDocIds(querys []utils.FSSearchQuery, filteds []utils.FSSearchFilted, bitmap *utils.Bitmap, indocids []utils.DocIdNode, maxdocid uint32) ([]utils.DocIdNode, bool) {

	start := len(indocids)
	flag := false
	var ok bool

	if len(querys) == 0 || querys == nil {
		docids := make([]utils.DocIdNode, 0)
		for i := this.StartDocId; i < this.MaxDocId; i++ {
			docids = append(docids, utils.DocIdNode{Docid: i})
		}
		indocids = append(indocids, docids...)
	} else {
		for _, query := range querys {
			if _, hasField := this.fields[query.FieldName]; !hasField {
				this.Logger.Info("[INFO] Field %v not found", query.FieldName)
				return indocids[:start], false
			}
			docids, match := this.fields[query.FieldName].query(query.Value)
			//  this.Logger.Info("[INFO] key[%v] len:%v",query.Value,len(docids))
			if !match {
				return indocids[:start], false
			}

			if !flag {
				flag = true
				indocids = append(indocids, docids...)

			} else {
				indocids, ok = utils.InteractionWithStart(indocids, docids, start)
				if !ok {
					return indocids[:start], false
				}

			}
		}

	}
	this.Logger.Info("[INFO] ResLen[%v] ", len(indocids))
	//bitmap去掉数据
	index := start

	if filteds == nil && bitmap != nil {
		for _, docid := range indocids[start:] {
			//去掉bitmap删除的
			if bitmap.GetBit(uint64(docid.Docid)) == 0 {
				indocids[index] = docid
				index++
			}
		}
		if index == start {
			return indocids[:start], false
		}
		return indocids[:index], true
	}

	//过滤操作
	index = start
	for _, docidinfo := range indocids[start:] {
		match := true
		for _, filter := range filteds {
			if _, hasField := this.fields[filter.FieldName]; hasField {
				if (bitmap != nil && bitmap.GetBit(uint64(docidinfo.Docid)) == 1) ||
					(!this.fields[filter.FieldName].filter(docidinfo.Docid, filter.Type, filter.Start, filter.End, filter.Range, filter.MatchStr)) {
					match = false
					break
				}
				this.Logger.Debug("[DEBUG] SEGMENT[%v] QUERY  %v", this.SegmentName, docidinfo)
			} else {
				this.Logger.Error("[ERROR] SEGMENT[%v] FILTER FIELD[%v] NOT FOUND", this.SegmentName, filter.FieldName)
				return indocids[:start], false
			}
		}
		if match {
			indocids[index] = docidinfo
			index++
		}

	}

	if index == start {
		return indocids[:start], false
	}
	return indocids[:index], true

}
Example #2
0
func (this *Segment) SearchDocIds(query utils.FSSearchQuery,
	filteds []utils.FSSearchFilted,
	bitmap *utils.Bitmap,
	indocids []utils.DocIdNode) ([]utils.DocIdNode, bool) {

	start := len(indocids)
	//query查询
	if query.Value == "" {
		docids := make([]utils.DocIdNode, 0)
		for i := this.StartDocId; i < this.MaxDocId; i++ {
			if bitmap.GetBit(uint64(i)) == 0 {
				docids = append(docids, utils.DocIdNode{Docid: i})
			}
		}
		indocids = append(indocids, docids...)
	} else {
		docids, match := this.fields[query.FieldName].query(query.Value)
		// this.Logger.Info("[INFO] key[%v] len:%v",query.Value,len(docids))
		if !match {
			return indocids, false
		}

		indocids = append(indocids, docids...)
	}

	//bitmap去掉数据
	index := start
	if (filteds == nil || len(filteds) == 0) && bitmap != nil {
		for _, docid := range indocids[start:] {
			//去掉bitmap删除的
			if bitmap.GetBit(uint64(docid.Docid)) == 0 {
				indocids[index] = docid
				index++
			}
		}
		return indocids[:index], true
	}

	//过滤操作
	index = start
	for _, docidinfo := range indocids[start:] {
		match := true
		for _, filter := range filteds {
			if _, hasField := this.fields[filter.FieldName]; hasField {
				if (bitmap != nil && bitmap.GetBit(uint64(docidinfo.Docid)) == 1) ||
					(!this.fields[filter.FieldName].filter(docidinfo.Docid, filter.Type, filter.Start, filter.End, filter.Range, filter.MatchStr)) {
					match = false
					break
				}
				this.Logger.Debug("[DEBUG] SEGMENT[%v] QUERY  %v", this.SegmentName, docidinfo)
			} else {
				this.Logger.Error("[ERROR] SEGMENT[%v] FILTER FIELD[%v] NOT FOUND", this.SegmentName, filter.FieldName)
				return indocids[:start], true
			}
		}
		if match {
			indocids[index] = docidinfo
			index++
		}

	}

	return indocids[:index], true

}