diff --git a/build.go b/build.go index 7a8dce0..1b73183 100644 --- a/build.go +++ b/build.go @@ -22,7 +22,7 @@ import ( "github.com/couchbase/vellum" ) -const Version uint32 = 14 +const Version uint32 = 15 const Type string = "zap" diff --git a/merge.go b/merge.go index 805100f..1de0deb 100644 --- a/merge.go +++ b/merge.go @@ -487,7 +487,12 @@ func mergeTermFreqNormLocs(fieldsMap map[string]uint16, term []byte, postItr *Po newRoaring.Add(uint32(hitNewDocNum)) nextFreq := next.Frequency() - nextNorm := uint64(math.Float32bits(float32(next.Norm()))) + var nextNorm uint64 + if pi, ok := next.(*Posting); ok { + nextNorm = pi.NormUint64() + } else { + return 0, 0, 0, nil, fmt.Errorf("unexpected posting type %T", next) + } locs := next.Locations() diff --git a/new.go b/new.go index 9815818..c10a6a0 100644 --- a/new.go +++ b/new.go @@ -456,7 +456,7 @@ func (s *interim) processDocument(docNum uint64, // now that it's been rolled up into fieldTFs, walk that for fieldID, tfs := range fieldTFs { dict := s.Dicts[fieldID] - norm := float32(1.0 / math.Sqrt(float64(fieldLens[fieldID]))) + norm := math.Float32frombits(uint32(fieldLens[fieldID])) for term, tf := range tfs { pid := dict[term] - 1 diff --git a/posting.go b/posting.go index 3a6ee54..53521ab 100644 --- a/posting.go +++ b/posting.go @@ -92,7 +92,7 @@ func under32Bits(x uint64) bool { const DocNum1HitFinished = math.MaxUint64 -var NormBits1Hit = uint64(math.Float32bits(float32(1))) +var NormBits1Hit = uint64(1) // PostingsList is an in-memory representation of a postings list type PostingsList struct { @@ -748,7 +748,7 @@ func (p *Posting) Frequency() uint64 { // Norm returns the normalization factor for this posting func (p *Posting) Norm() float64 { - return float64(p.norm) + return float64(float32(1.0 / math.Sqrt(float64(math.Float32bits(p.norm))))) } // Locations returns the location information for each occurrence @@ -756,6 +756,11 @@ func (p *Posting) Locations() []segment.Location { return p.locs } +// NormUint64 returns the norm value as uint64 +func (p *Posting) NormUint64() uint64 { + return uint64(math.Float32bits(p.norm)) +} + // Location represents the location of a single occurrence type Location struct { field string