0
0
Fork 0

scorch optimize mem processDocument() norm calculation

This change moves the norm calculation outside of the inner loop.
This commit is contained in:
Steve Yen 2018-03-03 11:58:28 -08:00
parent 6ae799052a
commit 884da6f93a
1 changed files with 2 additions and 1 deletions

View File

@ -253,12 +253,13 @@ func (s *Segment) processDocument(result *index.AnalysisResult) {
// now that its been rolled up into docMap, walk that
for fieldID, tokenFrequencies := range docMap {
dict := s.Dicts[fieldID]
norm := float32(1.0/math.Sqrt(float64(fieldLens[fieldID])))
for term, tokenFreq := range tokenFrequencies {
pid := dict[term] - 1
bs := s.Postings[pid]
bs.AddInt(int(docNum))
s.Freqs[pid] = append(s.Freqs[pid], uint64(tokenFreq.Frequency()))
s.Norms[pid] = append(s.Norms[pid], float32(1.0/math.Sqrt(float64(fieldLens[fieldID]))))
s.Norms[pid] = append(s.Norms[pid], norm)
locationBS := s.PostingsLocs[pid]
if len(tokenFreq.Locations) > 0 {
locationBS.AddInt(int(docNum))