diff --git a/index/upside_down/analysis.go b/index/upside_down/analysis.go index c6d94df3..43bf99f1 100644 --- a/index/upside_down/analysis.go +++ b/index/upside_down/analysis.go @@ -54,9 +54,7 @@ func (udc *UpsideDownCouch) Analyze(d *document.Document) *index.AnalysisResult } if storable && field.Options().IsStored() { - storeRows, indexBackIndexStoreEntries := udc.storeField(docIDBytes, field, fieldIndex) - rv.Rows = append(rv.Rows, storeRows...) - backIndexStoredEntries = append(backIndexStoredEntries, indexBackIndexStoreEntries...) + rv.Rows, backIndexStoredEntries = udc.storeField(docIDBytes, field, fieldIndex, rv.Rows, backIndexStoredEntries) } } @@ -94,9 +92,7 @@ func (udc *UpsideDownCouch) Analyze(d *document.Document) *index.AnalysisResult includeTermVectors := fieldIncludeTermVectors[fieldIndex] // encode this field - indexRows, indexBackIndexTermEntries := udc.indexField(docIDBytes, includeTermVectors, fieldIndex, fieldLength, tokenFreqs) - rv.Rows = append(rv.Rows, indexRows...) - backIndexTermEntries = append(backIndexTermEntries, indexBackIndexTermEntries...) + rv.Rows, backIndexTermEntries = udc.indexField(docIDBytes, includeTermVectors, fieldIndex, fieldLength, tokenFreqs, rv.Rows, backIndexTermEntries) } // build the back index row diff --git a/index/upside_down/upside_down.go b/index/upside_down/upside_down.go index 96295214..03b660e1 100644 --- a/index/upside_down/upside_down.go +++ b/index/upside_down/upside_down.go @@ -473,18 +473,14 @@ func (udc *UpsideDownCouch) mergeOldAndNew(backIndexRow *BackIndexRow, rows []in return addRows, updateRows, deleteRows } -func (udc *UpsideDownCouch) storeField(docID []byte, field document.Field, fieldIndex uint16) ([]index.IndexRow, []*BackIndexStoreEntry) { - rows := make([]index.IndexRow, 0, 100) - backIndexStoredEntries := make([]*BackIndexStoreEntry, 0) +func (udc *UpsideDownCouch) storeField(docID []byte, field document.Field, fieldIndex uint16, rows []index.IndexRow, backIndexStoredEntries []*BackIndexStoreEntry) ([]index.IndexRow, []*BackIndexStoreEntry) { fieldType := encodeFieldType(field) storedRow := NewStoredRow(docID, fieldIndex, field.ArrayPositions(), fieldType, field.Value()) // record the back index entry backIndexStoredEntry := BackIndexStoreEntry{Field: proto.Uint32(uint32(fieldIndex)), ArrayPositions: field.ArrayPositions()} - backIndexStoredEntries = append(backIndexStoredEntries, &backIndexStoredEntry) - rows = append(rows, storedRow) - return rows, backIndexStoredEntries + return append(rows, storedRow), append(backIndexStoredEntries, &backIndexStoredEntry) } func encodeFieldType(f document.Field) byte { @@ -502,10 +498,7 @@ func encodeFieldType(f document.Field) byte { return fieldType } -func (udc *UpsideDownCouch) indexField(docID []byte, includeTermVectors bool, fieldIndex uint16, fieldLength int, tokenFreqs analysis.TokenFrequencies) ([]index.IndexRow, []*BackIndexTermEntry) { - - rows := make([]index.IndexRow, 0, 100) - backIndexTermEntries := make([]*BackIndexTermEntry, 0, len(tokenFreqs)) +func (udc *UpsideDownCouch) indexField(docID []byte, includeTermVectors bool, fieldIndex uint16, fieldLength int, tokenFreqs analysis.TokenFrequencies, rows []index.IndexRow, backIndexTermEntries []*BackIndexTermEntry) ([]index.IndexRow, []*BackIndexTermEntry) { fieldNorm := float32(1.0 / math.Sqrt(float64(fieldLength))) for k, tf := range tokenFreqs {