From 6d5f17414222692052945c5ec4742eb49da2e94e Mon Sep 17 00:00:00 2001
From: Gao <chao.gao@zilliz.com>
Date: Mon, 20 Jan 2025 10:59:10 +0800
Subject: [PATCH] enhance: [2.5] add recalls response for restful api (#39409)

issue: #37899
pr: #39408

Signed-off-by: chasingegg <chao.gao@zilliz.com>
---
 internal/distributed/proxy/httpserver/constant.go   | 1 +
 internal/distributed/proxy/httpserver/handler_v2.go | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/internal/distributed/proxy/httpserver/constant.go b/internal/distributed/proxy/httpserver/constant.go
index a4e34c241f0d4..1a58f650f0dd0 100644
--- a/internal/distributed/proxy/httpserver/constant.go
+++ b/internal/distributed/proxy/httpserver/constant.go
@@ -120,6 +120,7 @@ const (
 	HTTPReturnMessage        = "message"
 	HTTPReturnData           = "data"
 	HTTPReturnCost           = "cost"
+	HTTPReturnRecalls        = "recalls"
 	HTTPReturnLoadState      = "loadState"
 	HTTPReturnLoadProgress   = "loadProgress"
 
diff --git a/internal/distributed/proxy/httpserver/handler_v2.go b/internal/distributed/proxy/httpserver/handler_v2.go
index 3d7c2daaca177..be64935412cad 100644
--- a/internal/distributed/proxy/httpserver/handler_v2.go
+++ b/internal/distributed/proxy/httpserver/handler_v2.go
@@ -1142,7 +1142,11 @@ func (h *HandlersV2) search(ctx context.Context, c *gin.Context, anyReq any, dbN
 					HTTPReturnMessage: merr.ErrInvalidSearchResult.Error() + ", error: " + err.Error(),
 				})
 			} else {
-				HTTPReturnStream(c, http.StatusOK, gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: outputData, HTTPReturnCost: cost})
+				if len(searchResp.Results.Recalls) > 0 {
+					HTTPReturnStream(c, http.StatusOK, gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: outputData, HTTPReturnCost: cost, HTTPReturnRecalls: searchResp.Results.Recalls})
+				} else {
+					HTTPReturnStream(c, http.StatusOK, gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: outputData, HTTPReturnCost: cost})
+				}
 			}
 		}
 	}