Example #1
0
func (c *TermVectorsConsumer) finishDocument() (err error) {
	c.docWriter.testPoint("TermVectorsTermsWriter.finishDocument start")

	if !c.hasVectors {
		return
	}

	// Fields in term vectors are UTF16 sorted: (?)
	util.IntroSort(TermVectorsConsumerPerFields(c.perFields[:c.numVectorsFields]))

	if err = c.initTermVectorsWriter(); err != nil {
		return
	}

	if err = c.fill(c.docState.docID); err != nil {
		return
	}

	// Append term vectors to the real outputs:
	if err = c.writer.StartDocument(c.numVectorsFields); err != nil {
		return
	}
	for i := 0; i < c.numVectorsFields; i++ {
		if err = c.perFields[i].finishDocument(); err != nil {
			return
		}
	}
	if err = c.writer.FinishDocument(); err != nil {
		return
	}

	assert2(c.lastDocId == c.docState.docID,
		"lastDocID=%v docState.docID=%v",
		c.lastDocId, c.docState.docID)

	c.lastDocId++

	c.TermsHashImpl.reset()
	c.resetFields()
	c.docWriter.testPoint("TermVectorsTermsWriter.finishDocument end")
	return
}
Example #2
0
func (w *FreqProxTermsWriter) flush(fieldsToFlush map[string]TermsHashPerField,
	state *model.SegmentWriteState) (err error) {

	if err = w.TermsHashImpl.flush(fieldsToFlush, state); err != nil {
		return
	}

	// Gather all FieldData's that have postings, across all ThreadStates
	var allFields []*FreqProxTermsWriterPerField

	for _, f := range fieldsToFlush {
		if perField := f.(*FreqProxTermsWriterPerField); perField.bytesHash.Size() > 0 {
			allFields = append(allFields, perField)
		}
	}

	// Sort by field name
	util.IntroSort(FreqProxTermsWriterPerFields(allFields))

	var consumer FieldsConsumer
	if consumer, err = state.SegmentInfo.Codec().(Codec).PostingsFormat().FieldsConsumer(state); err != nil {
		return
	}

	var success = false
	defer func() {
		if success {
			err = util.Close(consumer)
		} else {
			util.CloseWhileSuppressingError(consumer)
		}
	}()

	var termsHash TermsHash
	// Current writer chain:
	// FieldsConsumer
	// -> IMPL: FormatPostingsTermsDictWriter
	// -> TermsConsumer
	// -> IMPL: FormatPostingsTermsDictWriter.TermsWriter
	// -> DocsConsumer
	// -> IMPL: FormatPostingsDocWriter
	// -> PositionsConsumer
	// -> IMPL: FormatPostingsPositionsWriter

	for _, fieldWriter := range allFields {
		fieldInfo := fieldWriter.fieldInfo

		// If this field has postings then add them to the segment
		if err = fieldWriter.flush(fieldInfo.Name, consumer, state); err != nil {
			return
		}

		assert(termsHash == nil || termsHash == fieldWriter.termsHash)
		termsHash = fieldWriter.termsHash
		fieldWriter.reset()
	}

	if termsHash != nil {
		termsHash.reset()
	}
	success = true
	return nil
}