Example #1
0
func newFieldReader(owner *BlockTreeTermsReader,
	fieldInfo FieldInfo, numTerms int64, rootCode []byte,
	sumTotalTermFreq, sumDocFreq int64, docCount int32, indexStartFP int64,
	indexIn store.IndexInput) (r FieldReader, err error) {
	log.Print("Initializing FieldReader...")
	if numTerms <= 0 {
		panic("assert fail")
	}
	// assert numTerms > 0
	r = FieldReader{
		BlockTreeTermsReader: owner,
		fieldInfo:            fieldInfo,
		numTerms:             numTerms,
		sumTotalTermFreq:     sumTotalTermFreq,
		sumDocFreq:           sumDocFreq,
		docCount:             docCount,
		indexStartFP:         indexStartFP,
		rootCode:             rootCode,
	}
	log.Printf("BTTR: seg=%v field=%v rootBlockCode=%v divisor=",
		owner.segment, fieldInfo.name, rootCode)

	in := store.NewByteArrayDataInput(rootCode)
	n, err := in.ReadVLong()
	if err != nil {
		return r, err
	}
	r.rootBlockFP = int64(uint64(n) >> BTT_OUTPUT_FLAGS_NUM_BITS)

	if indexIn != nil {
		clone := indexIn.Clone()
		log.Printf("start=%v field=%v", indexStartFP, fieldInfo.name)
		clone.Seek(indexStartFP)
		r.index, err = util.LoadFST(clone, util.ByteSequenceOutputsSingleton())
	}

	return r, err
}
Example #2
0
func (e *SegmentTermsEnum) printSeekState() {
	if e.currentFrame == e.staticFrame {
		log.Println("  no prior seek")
	} else {
		log.Println("  prior seek state:")
		ord := 0
		isSeekFrame := true
		for {
			f := e.frame(ord)
			if f == nil {
				panic("assert fail")
			}
			prefix := e.term[0:f.prefix]
			if f.nextEnt == -1 {
				action := "(next)"
				if isSeekFrame {
					action = "(seek)"
				}
				fpOrigValue := ""
				if f.isFloor {
					fpOrigValue = fmt.Sprintf(" (fpOrig=%v", f.fpOrig)
				}
				code := (f.fp << BTT_OUTPUT_FLAGS_NUM_BITS)
				if f.hasTerms {
					code += BTT_OUTPUT_FLAG_HAS_TERMS
				}
				if f.isFloor {
					code += BTT_OUTPUT_FLAG_IS_FLOOR
				}
				log.Printf("    frame %v ord=%v fp=%v%v prefixLen=%v prefix=%v hasTerms=%v isFloor=%v code=%v isLastInFloor=%v mdUpto=%v tbOrd=%v",
					action, ord, f.fp, fpOrigValue, f.prefix, prefix, f.hasTerms, f.isFloor, code, f.isLastInFloor, f.metaDataUpto, f.getTermBlockOrd())
			} else {
				action := "(next, loaded)"
				if isSeekFrame {
					action = "(seek, loaded)"
				}
				fpOrigValue := ""
				if f.isFloor {
					fpOrigValue = fmt.Sprintf(" (fpOrig=%v", f.fpOrig)
				}
				code := (f.fp << BTT_OUTPUT_FLAGS_NUM_BITS)
				if f.hasTerms {
					code += BTT_OUTPUT_FLAG_HAS_TERMS
				}
				if f.isFloor {
					code += BTT_OUTPUT_FLAG_IS_FLOOR
				}
				log.Printf("    frame %v ord=%v fp=%v prefixLen=%v prefix=%v nextEnt=%v (of %v) hasTerms=%v isFloor=%v code=%v lastSubFP=%v isLastInFloor=%v mdUpto=%v tbOrd=%v",
					action, ord, f.fp, fpOrigValue, f.prefix, prefix, f.nextEnt, f.entCount, f.hasTerms, f.isFloor, code, f.lastSubFP, f.isLastInFloor, f.metaDataUpto, f.getTermBlockOrd())
			}
			if e.index != nil {
				if isSeekFrame && f.arc == nil {
					log.Printf("isSeekFrame=%v f.arc=%v", isSeekFrame, f.arc)
					panic("assert fail")
				}
				ret, err := util.GetFSTOutput(e.index, prefix)
				if err != nil {
					panic(err)
				}
				output := ret.([]byte)
				if output == nil {
					log.Println("      broken seek state: prefix is not final in index")
					panic("seek state is broken")
				} else if isSeekFrame && !f.isFloor {
					reader := store.NewByteArrayDataInput(output)
					codeOrig, _ := reader.ReadVLong()
					code := f.fp << BTT_OUTPUT_FLAGS_NUM_BITS
					if f.hasTerms {
						code += BTT_OUTPUT_FLAG_HAS_TERMS
					}
					if f.isFloor {
						code += BTT_OUTPUT_FLAG_IS_FLOOR
					}
					if codeOrig != code {
						log.Printf("      broken seek state: output code=%v doesn't match frame code=%v", codeOrig, code)
						panic("seek state is broken")
					}
				}
			}
			if f == e.currentFrame {
				break
			}
			if f.prefix == e.validIndexPrefix {
				isSeekFrame = false
			}
			ord++
		}
	}
}