Merge pull request #514 from steveyen/master
more upsidedown optimizations
This commit is contained in:
commit
269cc302e3
|
@ -499,6 +499,15 @@ func (udc *UpsideDownCouch) Update(doc *document.Document) (err error) {
|
|||
|
||||
func (udc *UpsideDownCouch) mergeOldAndNew(backIndexRow *BackIndexRow, rows []index.IndexRow) (addRows []UpsideDownCouchRow, updateRows []UpsideDownCouchRow, deleteRows []UpsideDownCouchRow) {
|
||||
addRows = make([]UpsideDownCouchRow, 0, len(rows))
|
||||
|
||||
if backIndexRow == nil {
|
||||
addRows = addRows[0:len(rows)]
|
||||
for i, row := range rows {
|
||||
addRows[i] = row
|
||||
}
|
||||
return addRows, nil, nil
|
||||
}
|
||||
|
||||
updateRows = make([]UpsideDownCouchRow, 0, len(rows))
|
||||
deleteRows = make([]UpsideDownCouchRow, 0, len(rows))
|
||||
|
||||
|
@ -604,14 +613,18 @@ func encodeFieldType(f document.Field) byte {
|
|||
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)))
|
||||
|
||||
termFreqRows := make([]TermFrequencyRow, len(tokenFreqs))
|
||||
termFreqRowsUsed := 0
|
||||
|
||||
for k, tf := range tokenFreqs {
|
||||
var termFreqRow *TermFrequencyRow
|
||||
termFreqRow := &termFreqRows[termFreqRowsUsed]
|
||||
termFreqRowsUsed++
|
||||
|
||||
InitTermFrequencyRow(termFreqRow, tf.Term, fieldIndex, docID,
|
||||
uint64(frequencyFromTokenFreq(tf)), fieldNorm)
|
||||
|
||||
if includeTermVectors {
|
||||
var tv []*TermVector
|
||||
tv, rows = udc.termVectorsFromTokenFreq(fieldIndex, tf, rows)
|
||||
termFreqRow = NewTermFrequencyRowWithTermVectors(tf.Term, fieldIndex, docID, uint64(frequencyFromTokenFreq(tf)), fieldNorm, tv)
|
||||
} else {
|
||||
termFreqRow = NewTermFrequencyRow(tf.Term, fieldIndex, docID, uint64(frequencyFromTokenFreq(tf)), fieldNorm)
|
||||
termFreqRow.vectors, rows = udc.termVectorsFromTokenFreq(fieldIndex, tf, rows)
|
||||
}
|
||||
|
||||
// record the back index entry
|
||||
|
@ -727,6 +740,7 @@ func frequencyFromTokenFreq(tf *analysis.TokenFreq) int {
|
|||
}
|
||||
|
||||
func (udc *UpsideDownCouch) termVectorsFromTokenFreq(field uint16, tf *analysis.TokenFreq, rows []index.IndexRow) ([]*TermVector, []index.IndexRow) {
|
||||
a := make([]TermVector, len(tf.Locations))
|
||||
rv := make([]*TermVector, len(tf.Locations))
|
||||
|
||||
for i, l := range tf.Locations {
|
||||
|
@ -739,14 +753,14 @@ func (udc *UpsideDownCouch) termVectorsFromTokenFreq(field uint16, tf *analysis.
|
|||
rows = append(rows, newFieldRow)
|
||||
}
|
||||
}
|
||||
tv := TermVector{
|
||||
a[i] = TermVector{
|
||||
field: fieldIndex,
|
||||
arrayPositions: l.ArrayPositions,
|
||||
pos: uint64(l.Position),
|
||||
start: uint64(l.Start),
|
||||
end: uint64(l.End),
|
||||
}
|
||||
rv[i] = &tv
|
||||
rv[i] = &a[i]
|
||||
}
|
||||
|
||||
return rv, rows
|
||||
|
|
Loading…
Reference in New Issue
Block a user