2023-04-11 15:40:31 +08:00
|
|
|
package segments
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2023-04-11 15:40:31 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/segcorepb"
|
|
|
|
)
|
|
|
|
|
|
|
|
type defaultLimitReducer struct {
|
|
|
|
req *querypb.QueryRequest
|
|
|
|
schema *schemapb.CollectionSchema
|
|
|
|
}
|
|
|
|
|
2023-09-18 11:39:20 +08:00
|
|
|
type mergeParam struct {
|
|
|
|
limit int64
|
|
|
|
outputFieldsId []int64
|
|
|
|
schema *schemapb.CollectionSchema
|
|
|
|
mergeStopForBest bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMergeParam(limit int64, outputFieldsId []int64, schema *schemapb.CollectionSchema, reduceStopForBest bool) *mergeParam {
|
|
|
|
return &mergeParam{
|
|
|
|
limit: limit,
|
|
|
|
outputFieldsId: outputFieldsId,
|
|
|
|
schema: schema,
|
|
|
|
mergeStopForBest: reduceStopForBest,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 15:40:31 +08:00
|
|
|
func (r *defaultLimitReducer) Reduce(ctx context.Context, results []*internalpb.RetrieveResults) (*internalpb.RetrieveResults, error) {
|
2023-09-18 11:39:20 +08:00
|
|
|
reduceParam := NewMergeParam(r.req.GetReq().GetLimit(), r.req.GetReq().GetOutputFieldsId(),
|
|
|
|
r.schema, r.req.GetReq().GetReduceStopForBest())
|
|
|
|
return mergeInternalRetrieveResultsAndFillIfEmpty(ctx, results, reduceParam)
|
2023-04-11 15:40:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func newDefaultLimitReducer(req *querypb.QueryRequest, schema *schemapb.CollectionSchema) *defaultLimitReducer {
|
|
|
|
return &defaultLimitReducer{
|
|
|
|
req: req,
|
|
|
|
schema: schema,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type defaultLimitReducerSegcore struct {
|
2024-05-15 17:53:34 +08:00
|
|
|
req *querypb.QueryRequest
|
|
|
|
schema *schemapb.CollectionSchema
|
|
|
|
manager *Manager
|
2023-04-11 15:40:31 +08:00
|
|
|
}
|
|
|
|
|
2024-04-25 09:49:26 +08:00
|
|
|
func (r *defaultLimitReducerSegcore) Reduce(ctx context.Context, results []*segcorepb.RetrieveResults, segments []Segment, plan *RetrievePlan) (*segcorepb.RetrieveResults, error) {
|
2023-09-18 11:39:20 +08:00
|
|
|
mergeParam := NewMergeParam(r.req.GetReq().GetLimit(), r.req.GetReq().GetOutputFieldsId(), r.schema, r.req.GetReq().GetReduceStopForBest())
|
2024-05-15 17:53:34 +08:00
|
|
|
return mergeSegcoreRetrieveResultsAndFillIfEmpty(ctx, results, mergeParam, segments, plan, r.manager)
|
2023-04-11 15:40:31 +08:00
|
|
|
}
|
|
|
|
|
2024-05-15 17:53:34 +08:00
|
|
|
func newDefaultLimitReducerSegcore(req *querypb.QueryRequest, schema *schemapb.CollectionSchema, manager *Manager) *defaultLimitReducerSegcore {
|
2023-04-11 15:40:31 +08:00
|
|
|
return &defaultLimitReducerSegcore{
|
2024-05-15 17:53:34 +08:00
|
|
|
req: req,
|
|
|
|
schema: schema,
|
|
|
|
manager: manager,
|
2023-04-11 15:40:31 +08:00
|
|
|
}
|
|
|
|
}
|