From 884da6f93a3c0b9a4567501ad4ddf96eea739227 Mon Sep 17 00:00:00 2001 From: Steve Yen Date: Sat, 3 Mar 2018 11:58:28 -0800 Subject: [PATCH] scorch optimize mem processDocument() norm calculation This change moves the norm calculation outside of the inner loop. --- index/scorch/segment/mem/build.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index/scorch/segment/mem/build.go b/index/scorch/segment/mem/build.go index 3a892f9a..643ae36e 100644 --- a/index/scorch/segment/mem/build.go +++ b/index/scorch/segment/mem/build.go @@ -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))