Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions internal/proxy/highlighter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (

type Highlighter interface {
AsSearchPipelineOperator(t *searchTask) (operator, error)
FieldIDs() []int64
}

// highlight task for one field
Expand Down Expand Up @@ -114,18 +115,26 @@ func (h *LexicalHighlighter) addTaskWithQuery(fieldID int64, query *highlightQue
})
}

func (h *LexicalHighlighter) AsSearchPipelineOperator(t *searchTask) (operator, error) {
func (h *LexicalHighlighter) initHighlightQueries(t *searchTask) error {
// add query to highlight tasks
for _, query := range h.queries {
fieldID, ok := t.schema.MapFieldID(query.fieldName)
if !ok {
return nil, merr.WrapErrParameterInvalidMsg("highlight field not found in schema: %s", query.fieldName)
return merr.WrapErrParameterInvalidMsg("highlight field not found in schema: %s", query.fieldName)
}
h.addTaskWithQuery(fieldID, query)
}
return nil
}

func (h *LexicalHighlighter) AsSearchPipelineOperator(t *searchTask) (operator, error) {
return newLexicalHighlightOperator(t, lo.Values(h.tasks))
}

func (h *LexicalHighlighter) FieldIDs() []int64 {
return lo.Keys(h.tasks)
}

func NewLexicalHighlighter(highlighter *commonpb.Highlighter) (*LexicalHighlighter, error) {
params := funcutil.KeyValuePair2Map(highlighter.GetParams())
h := &LexicalHighlighter{
Expand Down
31 changes: 20 additions & 11 deletions internal/proxy/task_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,12 @@ func (t *searchTask) createLexicalHighlighter(highlighter *commonpb.Highlighter,
if err != nil {
return err
}
return h.addTaskWithSearchText(fieldId, fieldName, analyzerName, texts)
err = h.addTaskWithSearchText(fieldId, fieldName, analyzerName, texts)
if err != nil {
return err
}

return h.initHighlightQueries(t)
}
return nil
}
Expand Down Expand Up @@ -642,10 +647,24 @@ func (t *searchTask) initSearchRequest(ctx context.Context) error {
}
}

analyzer, err := funcutil.GetAttrByKeyFromRepeatedKV(AnalyzerKey, t.request.GetSearchParams())
if err == nil {
t.SearchRequest.AnalyzerName = analyzer
}

t.isIterator = isIterator
t.SearchRequest.Offset = offset
t.SearchRequest.FieldId = queryInfo.GetQueryFieldId()

if err := t.addHighlightTask(t.request.GetHighlighter(), queryInfo.GetMetricType(), queryInfo.GetQueryFieldId(), t.request.GetPlaceholderGroup(), t.SearchRequest.GetAnalyzerName()); err != nil {
return err
}

// add highlight field ids to output fields id
if t.highlighter != nil {
t.SearchRequest.OutputFieldsId = append(t.SearchRequest.OutputFieldsId, t.highlighter.FieldIDs()...)
}

if t.partitionKeyMode {
// isolation has tighter constraint, check first
mvErr := setQueryInfoIfMvEnable(queryInfo, t, plan)
Expand Down Expand Up @@ -696,16 +715,6 @@ func (t *searchTask) initSearchRequest(ctx context.Context) error {
t.SearchRequest.GroupByFieldId = queryInfo.GroupByFieldId
t.SearchRequest.GroupSize = queryInfo.GroupSize

if t.SearchRequest.MetricType == metric.BM25 {
analyzer, err := funcutil.GetAttrByKeyFromRepeatedKV(AnalyzerKey, t.request.GetSearchParams())
if err == nil {
t.SearchRequest.AnalyzerName = analyzer
}
}
if err := t.addHighlightTask(t.request.GetHighlighter(), t.SearchRequest.MetricType, t.SearchRequest.FieldId, t.request.GetPlaceholderGroup(), t.SearchRequest.GetAnalyzerName()); err != nil {
return err
}

if embedding.HasNonBM25Functions(t.schema.CollectionSchema.Functions, []int64{queryInfo.GetQueryFieldId()}) {
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-Search-call-function-udf")
defer sp.End()
Expand Down
Loading