当前位置: 首页>>代码示例>>Golang>>正文


Golang store.KVReader类代码示例

本文整理汇总了Golang中github.com/blevesearch/bleve/index/store.KVReader的典型用法代码示例。如果您正苦于以下问题:Golang KVReader类的具体用法?Golang KVReader怎么用?Golang KVReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了KVReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: backIndexRowForDoc

func backIndexRowForDoc(kvreader store.KVReader, docID index.IndexInternalID) (*BackIndexRow, error) {
	// use a temporary row structure to build key
	tempRow := &BackIndexRow{
		doc: docID,
	}

	keyBuf := GetRowBuffer()
	if tempRow.KeySize() > len(keyBuf) {
		keyBuf = make([]byte, 2*tempRow.KeySize())
	}
	defer PutRowBuffer(keyBuf)
	keySize, err := tempRow.KeyTo(keyBuf)
	if err != nil {
		return nil, err
	}

	value, err := kvreader.Get(keyBuf[:keySize])
	if err != nil {
		return nil, err
	}
	if value == nil {
		return nil, nil
	}
	backIndexRow, err := NewBackIndexRowKV(keyBuf[:keySize], value)
	if err != nil {
		return nil, err
	}
	return backIndexRow, nil
}
开发者ID:ekanite,项目名称:bleve,代码行数:29,代码来源:upside_down.go

示例2: dumpPrefix

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()
	}
}
开发者ID:bcampbell,项目名称:bleve,代码行数:29,代码来源:dump.go

示例3: dumpRange

func dumpRange(kvreader store.KVReader, rv chan interface{}, start, end []byte) {
	it := kvreader.RangeIterator(start, end)
	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()
	}
}
开发者ID:bcampbell,项目名称:bleve,代码行数:25,代码来源:dump.go

示例4: checkVersion

func (f *Firestorm) checkVersion(reader store.KVReader) (newIndex bool, err error) {
	value, err := reader.Get(VersionKey)
	if err != nil {
		return
	}

	if value == nil {
		newIndex = true
		return
	}

	var vr *VersionRow
	vr, err = NewVersionRowV(value)
	if err != nil {
		return
	}

	// assert correct version
	if vr.Version() != Version {
		err = IncompatibleVersion
		return
	}

	return
}
开发者ID:BobbWu,项目名称:bleve,代码行数:25,代码来源:version.go

示例5: dumpPrefix

func (udc *UpsideDownCouch) dumpPrefix(kvreader store.KVReader, rv chan interface{}, prefix []byte) {
	start := prefix
	if start == nil {
		start = []byte{0}
	}
	it := kvreader.Iterator(start)
	defer it.Close()
	key, val, valid := it.Current()
	for valid {

		if prefix != nil && !bytes.HasPrefix(key, prefix) {
			break
		}

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

		it.Next()
		key, val, valid = it.Current()
	}
}
开发者ID:jingweno,项目名称:bleve,代码行数:25,代码来源:dump.go

示例6: visitPrefix

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
}
开发者ID:MachineShop-IOT,项目名称:bleve,代码行数:28,代码来源:util.go

示例7: countDocs

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
}
开发者ID:ekanite,项目名称:bleve,代码行数:35,代码来源:smoldering.go

示例8: loadSchema

func (udc *UpsideDownCouch) loadSchema(kvreader store.KVReader) (err error) {

	keyPrefix := []byte{'f'}
	it := kvreader.Iterator(keyPrefix)
	defer it.Close()

	it.Seek(keyPrefix)
	key, val, valid := it.Current()
	for valid {

		// stop when
		if !bytes.HasPrefix(key, keyPrefix) {
			break
		}
		fieldRow, err := NewFieldRowKV(key, val)
		if err != nil {
			return err
		}
		udc.fieldIndexes[fieldRow.name] = fieldRow.index
		if int(fieldRow.index) > udc.lastFieldIndex {
			udc.lastFieldIndex = int(fieldRow.index)
		}

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

	return
}
开发者ID:jingweno,项目名称:bleve,代码行数:29,代码来源:upside_down.go

示例9: loadSchema

func (udc *UpsideDownCouch) loadSchema(kvreader store.KVReader) (err error) {

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

	it.Seek(keyPrefix)
	key, val, valid := it.Current()
	for valid {

		// stop when
		if !bytes.HasPrefix(key, keyPrefix) {
			break
		}
		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()
	}

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

	return
}
开发者ID:trebogeer,项目名称:bleve,代码行数:46,代码来源:upside_down.go

示例10: countDocs

func (udc *UpsideDownCouch) countDocs(kvreader store.KVReader) uint64 {
	it := kvreader.Iterator([]byte{'b'})
	defer it.Close()

	var rv uint64
	key, _, valid := it.Current()
	for valid {
		if !bytes.HasPrefix(key, []byte{'b'}) {
			break
		}
		rv++
		it.Next()
		key, _, valid = it.Current()
	}

	return rv
}
开发者ID:jingweno,项目名称:bleve,代码行数:17,代码来源:upside_down.go

示例11: countDocs

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
}
开发者ID:ekanite,项目名称:bleve,代码行数:17,代码来源:upside_down.go

示例12: backIndexRowForDoc

func (udc *UpsideDownCouch) backIndexRowForDoc(kvreader store.KVReader, docID string) (*BackIndexRow, error) {
	// use a temporary row structure to build key
	tempRow := &BackIndexRow{
		doc: []byte(docID),
	}
	key := tempRow.Key()
	value, err := kvreader.Get(key)
	if err != nil {
		return nil, err
	}
	if value == nil {
		return nil, nil
	}
	backIndexRow, err := NewBackIndexRowKV(key, value)
	if err != nil {
		return nil, err
	}
	return backIndexRow, nil
}
开发者ID:jingweno,项目名称:bleve,代码行数:19,代码来源:upside_down.go

示例13: dumpRange

func (udc *UpsideDownCouch) dumpRange(kvreader store.KVReader, rv chan interface{}, start, end []byte) {
	it := kvreader.RangeIterator(start, end)
	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()
	}
}
开发者ID:kevgs,项目名称:bleve,代码行数:22,代码来源:dump.go

示例14: loadSchema

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
}
开发者ID:ekanite,项目名称:bleve,代码行数:38,代码来源:smoldering.go

示例15: Delete

func (udc *UpsideDownCouch) Delete(id string) (err error) {
	indexStart := time.Now()

	udc.writeMutex.Lock()
	defer udc.writeMutex.Unlock()

	// open a reader for backindex lookup
	var kvreader store.KVReader
	kvreader, err = udc.store.Reader()
	if err != nil {
		return
	}

	// first we lookup the backindex row for the doc id if it exists
	// lookup the back index row
	var backIndexRow *BackIndexRow
	backIndexRow, err = backIndexRowForDoc(kvreader, index.IndexInternalID(id))
	if err != nil {
		_ = kvreader.Close()
		atomic.AddUint64(&udc.stats.errors, 1)
		return
	}

	err = kvreader.Close()
	if err != nil {
		return
	}

	if backIndexRow == nil {
		atomic.AddUint64(&udc.stats.deletes, 1)
		return
	}

	// start a writer for this delete
	var kvwriter store.KVWriter
	kvwriter, err = udc.store.Writer()
	if err != nil {
		return
	}
	defer func() {
		if cerr := kvwriter.Close(); err == nil && cerr != nil {
			err = cerr
		}
	}()

	var deleteRowsAll [][]UpsideDownCouchRow

	deleteRows := udc.deleteSingle(id, backIndexRow, nil)
	if len(deleteRows) > 0 {
		deleteRowsAll = append(deleteRowsAll, deleteRows)
	}

	err = udc.batchRows(kvwriter, nil, nil, deleteRowsAll)
	if err == nil {
		udc.m.Lock()
		udc.docCount--
		udc.m.Unlock()
	}
	atomic.AddUint64(&udc.stats.indexTime, uint64(time.Since(indexStart)))
	if err == nil {
		atomic.AddUint64(&udc.stats.deletes, 1)
	} else {
		atomic.AddUint64(&udc.stats.errors, 1)
	}
	return
}
开发者ID:ekanite,项目名称:bleve,代码行数:66,代码来源:upside_down.go


注:本文中的github.com/blevesearch/bleve/index/store.KVReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。