From 36861ddf9f6d58da663671ac86da182b1a45d786 Mon Sep 17 00:00:00 2001 From: Abhinav Dangeti Date: Fri, 5 Feb 2021 16:15:16 -0700 Subject: [PATCH] Fields/highlighting would only apply to "size" number of docs --- search.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/search.go b/search.go index cf1fe17a0..7397f566e 100644 --- a/search.go +++ b/search.go @@ -603,9 +603,11 @@ func MemoryNeededForSearchResult(req *SearchRequest) uint64 { // overhead from fields, highlighting var d document.Document if len(req.Fields) > 0 || req.Highlight != nil { - for i := 0; i < numDocMatches; i++ { - estimate += d.Size() + numDocsApplicable := req.Size + if numDocsApplicable > collector.PreAllocSizeSkipCap { + numDocsApplicable = collector.PreAllocSizeSkipCap } + estimate += numDocsApplicable * d.Size() } return uint64(estimate)