upside_down storeField/indexField append to provided arrays
Taking another optimization from firestorm, upside_down's storeField()/indexField() funcs now also append() to passed-in arrays rather than always allocating their own arrays.
This commit is contained in:
parent
1af2927967
commit
4eee8821f9
@ -54,9 +54,7 @@ func (udc *UpsideDownCouch) Analyze(d *document.Document) *index.AnalysisResult
|
|||||||
}
|
}
|
||||||
|
|
||||||
if storable && field.Options().IsStored() {
|
if storable && field.Options().IsStored() {
|
||||||
storeRows, indexBackIndexStoreEntries := udc.storeField(docIDBytes, field, fieldIndex)
|
rv.Rows, backIndexStoredEntries = udc.storeField(docIDBytes, field, fieldIndex, rv.Rows, backIndexStoredEntries)
|
||||||
rv.Rows = append(rv.Rows, storeRows...)
|
|
||||||
backIndexStoredEntries = append(backIndexStoredEntries, indexBackIndexStoreEntries...)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,9 +92,7 @@ func (udc *UpsideDownCouch) Analyze(d *document.Document) *index.AnalysisResult
|
|||||||
includeTermVectors := fieldIncludeTermVectors[fieldIndex]
|
includeTermVectors := fieldIncludeTermVectors[fieldIndex]
|
||||||
|
|
||||||
// encode this field
|
// encode this field
|
||||||
indexRows, indexBackIndexTermEntries := udc.indexField(docIDBytes, includeTermVectors, fieldIndex, fieldLength, tokenFreqs)
|
rv.Rows, backIndexTermEntries = udc.indexField(docIDBytes, includeTermVectors, fieldIndex, fieldLength, tokenFreqs, rv.Rows, backIndexTermEntries)
|
||||||
rv.Rows = append(rv.Rows, indexRows...)
|
|
||||||
backIndexTermEntries = append(backIndexTermEntries, indexBackIndexTermEntries...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// build the back index row
|
// build the back index row
|
||||||
|
@ -473,18 +473,14 @@ func (udc *UpsideDownCouch) mergeOldAndNew(backIndexRow *BackIndexRow, rows []in
|
|||||||
return addRows, updateRows, deleteRows
|
return addRows, updateRows, deleteRows
|
||||||
}
|
}
|
||||||
|
|
||||||
func (udc *UpsideDownCouch) storeField(docID []byte, field document.Field, fieldIndex uint16) ([]index.IndexRow, []*BackIndexStoreEntry) {
|
func (udc *UpsideDownCouch) storeField(docID []byte, field document.Field, fieldIndex uint16, rows []index.IndexRow, backIndexStoredEntries []*BackIndexStoreEntry) ([]index.IndexRow, []*BackIndexStoreEntry) {
|
||||||
rows := make([]index.IndexRow, 0, 100)
|
|
||||||
backIndexStoredEntries := make([]*BackIndexStoreEntry, 0)
|
|
||||||
fieldType := encodeFieldType(field)
|
fieldType := encodeFieldType(field)
|
||||||
storedRow := NewStoredRow(docID, fieldIndex, field.ArrayPositions(), fieldType, field.Value())
|
storedRow := NewStoredRow(docID, fieldIndex, field.ArrayPositions(), fieldType, field.Value())
|
||||||
|
|
||||||
// record the back index entry
|
// record the back index entry
|
||||||
backIndexStoredEntry := BackIndexStoreEntry{Field: proto.Uint32(uint32(fieldIndex)), ArrayPositions: field.ArrayPositions()}
|
backIndexStoredEntry := BackIndexStoreEntry{Field: proto.Uint32(uint32(fieldIndex)), ArrayPositions: field.ArrayPositions()}
|
||||||
backIndexStoredEntries = append(backIndexStoredEntries, &backIndexStoredEntry)
|
|
||||||
|
|
||||||
rows = append(rows, storedRow)
|
return append(rows, storedRow), append(backIndexStoredEntries, &backIndexStoredEntry)
|
||||||
return rows, backIndexStoredEntries
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeFieldType(f document.Field) byte {
|
func encodeFieldType(f document.Field) byte {
|
||||||
@ -502,10 +498,7 @@ func encodeFieldType(f document.Field) byte {
|
|||||||
return fieldType
|
return fieldType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (udc *UpsideDownCouch) indexField(docID []byte, includeTermVectors bool, fieldIndex uint16, fieldLength int, tokenFreqs analysis.TokenFrequencies) ([]index.IndexRow, []*BackIndexTermEntry) {
|
func (udc *UpsideDownCouch) indexField(docID []byte, includeTermVectors bool, fieldIndex uint16, fieldLength int, tokenFreqs analysis.TokenFrequencies, rows []index.IndexRow, backIndexTermEntries []*BackIndexTermEntry) ([]index.IndexRow, []*BackIndexTermEntry) {
|
||||||
|
|
||||||
rows := make([]index.IndexRow, 0, 100)
|
|
||||||
backIndexTermEntries := make([]*BackIndexTermEntry, 0, len(tokenFreqs))
|
|
||||||
fieldNorm := float32(1.0 / math.Sqrt(float64(fieldLength)))
|
fieldNorm := float32(1.0 / math.Sqrt(float64(fieldLength)))
|
||||||
|
|
||||||
for k, tf := range tokenFreqs {
|
for k, tf := range tokenFreqs {
|
||||||
|
Loading…
Reference in New Issue
Block a user