Skip to content

Commit

Permalink
Added missing nil check (#1905)
Browse files Browse the repository at this point in the history
In case a document is not found, a nil check is required since
`doc.StoredFieldsBytes()` then results in a panic.
  • Loading branch information
metonymic-smokey authored Nov 10, 2023
1 parent 907c83e commit 6dee5e9
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions index_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ func (i *indexImpl) SearchInContext(ctx context.Context, req *SearchRequest) (sr
ctx = context.WithValue(ctx, search.GeoBufferPoolCallbackKey,
search.GeoBufferPoolCallbackFunc(getBufferPool))


// Using a disjunction query to get union of results from KNN query
// and the original query
searchQuery := disjunctQueryWithKNN(req)
Expand Down Expand Up @@ -663,9 +662,9 @@ func LoadAndHighlightFields(hit *search.DocumentMatch, req *SearchRequest,
var totalStoredFieldsBytes uint64
if len(req.Fields) > 0 || highlighter != nil {
doc, err := r.Document(hit.ID)
totalStoredFieldsBytes = doc.StoredFieldsBytes()
if err == nil && doc != nil {
if len(req.Fields) > 0 {
totalStoredFieldsBytes = doc.StoredFieldsBytes()
fieldsToLoad := deDuplicate(req.Fields)
for _, f := range fieldsToLoad {
doc.VisitFields(func(docF index.Field) {
Expand Down

0 comments on commit 6dee5e9

Please sign in to comment.