예제 #1
0
파일: smoldering.go 프로젝트: ekanite/bleve
func (udc *SmolderingCouch) countDocs(kvreader store.KVReader) (count, highDocNum uint64, err error) {
	k := TermFrequencyRowStartField(0)
	it := kvreader.PrefixIterator(k)
	defer func() {
		if cerr := it.Close(); err == nil && cerr != nil {
			err = cerr
		}
	}()

	var lastValidDocNum []byte
	k, _, valid := it.Current()
	for valid {
		tfr, err := NewTermFrequencyRowK(k)
		if err != nil {
			return 0, 0, err
		}
		if tfr.term != nil {
			udc.cf.Insert(tfr.term)
		}
		lastValidDocNum = lastValidDocNum[:0]
		lastValidDocNum = append(lastValidDocNum, tfr.docNumber...)
		count++
		it.Next()
		k, _, valid = it.Current()
	}

	if lastValidDocNum != nil {
		_, highDocNum, err = DecodeUvarintAscending(lastValidDocNum)
		if err != nil {
			return 0, 0, err
		}
	}

	return
}
예제 #2
0
파일: dump.go 프로젝트: bcampbell/bleve
func dumpPrefix(kvreader store.KVReader, rv chan interface{}, prefix []byte) {
	start := prefix
	if start == nil {
		start = []byte{0}
	}
	it := kvreader.PrefixIterator(start)
	defer func() {
		cerr := it.Close()
		if cerr != nil {
			rv <- cerr
		}
	}()
	key, val, valid := it.Current()
	for valid {
		ck := make([]byte, len(key))
		copy(ck, key)
		cv := make([]byte, len(val))
		copy(cv, val)
		row, err := ParseFromKeyValue(ck, cv)
		if err != nil {
			rv <- err
			return
		}
		rv <- row

		it.Next()
		key, val, valid = it.Current()
	}
}
예제 #3
0
func visitPrefix(reader store.KVReader, prefix []byte, visitor KVVisitor) (err error) {
	start := prefix
	if start == nil {
		start = []byte{}
	}
	it := reader.PrefixIterator(start)
	defer func() {
		if cerr := it.Close(); err == nil && cerr != nil {
			err = cerr
		}
	}()
	k, v, valid := it.Current()
	for valid {
		var cont bool
		cont, err = visitor(k, v)
		if err != nil {
			// visitor encountered an error, stop and return it
			return
		}
		if !cont {
			// vistor has requested we stop iteration, return nil
			return
		}
		it.Next()
		k, v, valid = it.Current()
	}
	return
}
예제 #4
0
파일: dump.go 프로젝트: kevgs/bleve
func (udc *UpsideDownCouch) dumpPrefix(kvreader store.KVReader, rv chan interface{}, prefix []byte) {
	start := prefix
	if start == nil {
		start = []byte{0}
	}
	it := kvreader.PrefixIterator(start)
	defer func() {
		cerr := it.Close()
		if cerr != nil {
			rv <- cerr
		}
	}()
	key, val, valid := it.Current()
	for valid {

		row, err := ParseFromKeyValue(key, val)
		if err != nil {
			rv <- err
			return
		}
		rv <- row

		it.Next()
		key, val, valid = it.Current()
	}
}
예제 #5
0
func (udc *UpsideDownCouch) countDocs(kvreader store.KVReader) (count uint64, err error) {
	it := kvreader.PrefixIterator([]byte{'b'})
	defer func() {
		if cerr := it.Close(); err == nil && cerr != nil {
			err = cerr
		}
	}()

	_, _, valid := it.Current()
	for valid {
		count++
		it.Next()
		_, _, valid = it.Current()
	}

	return
}
예제 #6
0
파일: smoldering.go 프로젝트: ekanite/bleve
func (udc *SmolderingCouch) loadSchema(kvreader store.KVReader) (err error) {

	it := kvreader.PrefixIterator([]byte{'f'})
	defer func() {
		if cerr := it.Close(); err == nil && cerr != nil {
			err = cerr
		}
	}()

	key, val, valid := it.Current()
	for valid {
		var fieldRow *FieldRow
		fieldRow, err = NewFieldRowKV(key, val)
		if err != nil {
			return
		}
		udc.fieldCache.AddExisting(fieldRow.name, fieldRow.index)

		it.Next()
		key, val, valid = it.Current()
	}

	val, err = kvreader.Get([]byte{'v'})
	if err != nil {
		return
	}
	var vr *VersionRow
	vr, err = NewVersionRowKV([]byte{'v'}, val)
	if err != nil {
		return
	}
	if vr.version != Version {
		err = IncompatibleVersion
		return
	}

	return
}