Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MB-59102: Merging KNN Results #1910

Merged
merged 11 commits into from
Nov 21, 2023
10 changes: 9 additions & 1 deletion index_alias_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func (i *indexAliasImpl) SearchInContext(ctx context.Context, req *SearchRequest
if len(i.indexes) == 1 {
return i.indexes[0].SearchInContext(ctx, req)
}

return MultiSearch(ctx, req, i.indexes...)
}

Expand Down Expand Up @@ -453,6 +452,10 @@ func MultiSearch(ctx context.Context, req *SearchRequest, indexes ...Index) (*Se
req.SearchAfter = req.SearchBefore
req.SearchBefore = nil
}
originalSize := req.Size
if len(indexes) > 1 {
req.Size = adjustRequestSizeForKNN(req, len(indexes))
}

// run search on each index in separate go routine
var waitGroup sync.WaitGroup
Expand Down Expand Up @@ -491,6 +494,7 @@ func MultiSearch(ctx context.Context, req *SearchRequest, indexes ...Index) (*Se
indexErrors[asr.Name] = asr.Err
}
}
req.Size = originalSize

// merge just concatenated all the hits
// now lets clean it up
Expand All @@ -504,6 +508,10 @@ func MultiSearch(ctx context.Context, req *SearchRequest, indexes ...Index) (*Se
}
}

if len(indexes) > 1 {
mergeKNNResults(req, sr)
}

sortFunc := req.SortFunc()
// sort all hits with the requested order
if len(req.Sort) > 0 {
Expand Down
6 changes: 4 additions & 2 deletions index_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func (i *indexImpl) SearchInContext(ctx context.Context, req *SearchRequest) (sr
req.SearchAfter = nil
}

return &SearchResult{
rv := &SearchResult{
Status: &SearchStatus{
Total: 1,
Successful: 1,
Expand All @@ -653,7 +653,9 @@ func (i *indexImpl) SearchInContext(ctx context.Context, req *SearchRequest) (sr
MaxScore: coll.MaxScore(),
Took: searchDuration,
Facets: coll.FacetResults(),
}, nil
}
mergeKNNResults(req, rv)
return rv, nil
}

func LoadAndHighlightFields(hit *search.DocumentMatch, req *SearchRequest,
Expand Down
Loading
Loading