Skip to content

Commit cf3ea63

Browse files
committed
Add support for using highlight without returning the field as the output field.
Signed-off-by: aoiasd <[email protected]>
1 parent 73fdaaf commit cf3ea63

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

internal/proxy/highlighter.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const (
3636

3737
type Highlighter interface {
3838
AsSearchPipelineOperator(t *searchTask) (operator, error)
39+
FieldIDs() []int64
3940
}
4041

4142
// highlight task for one field
@@ -114,18 +115,26 @@ func (h *LexicalHighlighter) addTaskWithQuery(fieldID int64, query *highlightQue
114115
})
115116
}
116117

117-
func (h *LexicalHighlighter) AsSearchPipelineOperator(t *searchTask) (operator, error) {
118+
func (h *LexicalHighlighter) initHighlightQueries(t *searchTask) error {
118119
// add query to highlight tasks
119120
for _, query := range h.queries {
120121
fieldID, ok := t.schema.MapFieldID(query.fieldName)
121122
if !ok {
122-
return nil, merr.WrapErrParameterInvalidMsg("highlight field not found in schema: %s", query.fieldName)
123+
return merr.WrapErrParameterInvalidMsg("highlight field not found in schema: %s", query.fieldName)
123124
}
124125
h.addTaskWithQuery(fieldID, query)
125126
}
127+
return nil
128+
}
129+
130+
func (h *LexicalHighlighter) AsSearchPipelineOperator(t *searchTask) (operator, error) {
126131
return newLexicalHighlightOperator(t, lo.Values(h.tasks))
127132
}
128133

134+
func (h *LexicalHighlighter) FieldIDs() []int64 {
135+
return lo.Keys(h.tasks)
136+
}
137+
129138
func NewLexicalHighlighter(highlighter *commonpb.Highlighter) (*LexicalHighlighter, error) {
130139
params := funcutil.KeyValuePair2Map(highlighter.GetParams())
131140
h := &LexicalHighlighter{

internal/proxy/task_search.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,12 @@ func (t *searchTask) createLexicalHighlighter(highlighter *commonpb.Highlighter,
602602
if err != nil {
603603
return err
604604
}
605-
return h.addTaskWithSearchText(fieldId, fieldName, analyzerName, texts)
605+
err = h.addTaskWithSearchText(fieldId, fieldName, analyzerName, texts)
606+
if err != nil {
607+
return err
608+
}
609+
610+
return h.initHighlightQueries(t)
606611
}
607612
return nil
608613
}
@@ -642,10 +647,26 @@ func (t *searchTask) initSearchRequest(ctx context.Context) error {
642647
}
643648
}
644649

650+
if t.SearchRequest.MetricType == metric.BM25 {
651+
analyzer, err := funcutil.GetAttrByKeyFromRepeatedKV(AnalyzerKey, t.request.GetSearchParams())
652+
if err == nil {
653+
t.SearchRequest.AnalyzerName = analyzer
654+
}
655+
}
656+
645657
t.isIterator = isIterator
646658
t.SearchRequest.Offset = offset
647659
t.SearchRequest.FieldId = queryInfo.GetQueryFieldId()
648660

661+
if err := t.addHighlightTask(t.request.GetHighlighter(), queryInfo.GetMetricType(), queryInfo.GetQueryFieldId(), t.request.GetPlaceholderGroup(), t.SearchRequest.GetAnalyzerName()); err != nil {
662+
return err
663+
}
664+
665+
// add highlight field ids to output fields id
666+
if t.highlighter != nil {
667+
t.SearchRequest.OutputFieldsId = append(t.SearchRequest.OutputFieldsId, t.highlighter.FieldIDs()...)
668+
}
669+
649670
if t.partitionKeyMode {
650671
// isolation has tighter constraint, check first
651672
mvErr := setQueryInfoIfMvEnable(queryInfo, t, plan)
@@ -696,16 +717,6 @@ func (t *searchTask) initSearchRequest(ctx context.Context) error {
696717
t.SearchRequest.GroupByFieldId = queryInfo.GroupByFieldId
697718
t.SearchRequest.GroupSize = queryInfo.GroupSize
698719

699-
if t.SearchRequest.MetricType == metric.BM25 {
700-
analyzer, err := funcutil.GetAttrByKeyFromRepeatedKV(AnalyzerKey, t.request.GetSearchParams())
701-
if err == nil {
702-
t.SearchRequest.AnalyzerName = analyzer
703-
}
704-
}
705-
if err := t.addHighlightTask(t.request.GetHighlighter(), t.SearchRequest.MetricType, t.SearchRequest.FieldId, t.request.GetPlaceholderGroup(), t.SearchRequest.GetAnalyzerName()); err != nil {
706-
return err
707-
}
708-
709720
if embedding.HasNonBM25Functions(t.schema.CollectionSchema.Functions, []int64{queryInfo.GetQueryFieldId()}) {
710721
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-Search-call-function-udf")
711722
defer sp.End()

0 commit comments

Comments
 (0)