Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(search): add description api for search

LinkinStars51c86449e679
diff --git a/internal/controller/search_controller.go b/internal/controller/search_controller.go
index be47d1af..354c3423 100644
--- a/internal/controller/search_controller.go
+++ b/internal/controller/search_controller.go
@@ -10,6 +10,7 @@ import (
"github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/internal/service"
"github.com/answerdev/answer/internal/service/action"
+ "github.com/answerdev/answer/plugin"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/errors"
)
@@ -71,3 +72,24 @@ func (sc *SearchController) Search(ctx *gin.Context) {
resp, err := sc.searchService.Search(ctx, &dto)
handler.HandleResponse(ctx, err, resp)
}
+
+// SearchDesc get search description
+// @Summary get search description
+// @Description get search description
+// @Tags Search
+// @Produce json
+// @Success 200 {object} handler.RespBody{data=schema.SearchResp}
+// @Router /answer/api/v1/search/desc [get]
+func (sc *SearchController) SearchDesc(ctx *gin.Context) {
+ var finder plugin.Search
+ _ = plugin.CallSearch(func(search plugin.Search) error {
+ finder = search
+ return nil
+ })
+ resp := &schema.SearchDescResp{}
+ if finder != nil {
+ resp.Name = finder.Info().Name.Translate(ctx)
+ resp.Icon = finder.Description().Icon
+ }
+ handler.HandleResponse(ctx, nil, resp)
+}
diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go
index e02994a2..bbd32b6d 100644
--- a/internal/router/answer_api_router.go
+++ b/internal/router/answer_api_router.go
@@ -155,6 +155,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
//search
r.GET("/search", a.searchController.Search)
+ r.GET("/search/desc", a.searchController.SearchDesc)
//rank
r.GET("/personal/rank/page", a.rankController.GetRankPersonalWithPage)
diff --git a/internal/schema/search_schema.go b/internal/schema/search_schema.go
index 97728402..58585176 100644
--- a/internal/schema/search_schema.go
+++ b/internal/schema/search_schema.go
@@ -118,6 +118,9 @@ type SearchResp struct {
Total int64 `json:"count"`
// search response
SearchResults []SearchResult `json:"list"`
- // search plugin desc
- SearchPluginIcon string `json:"search_icon,omitempty"`
+}
+
+type SearchDescResp struct {
+ Name string `json:"name"`
+ Icon string `json:"icon"`
}
diff --git a/internal/service/search_service.go b/internal/service/search_service.go
index be5bada4..d4f74e92 100644
--- a/internal/service/search_service.go
+++ b/internal/service/search_service.go
@@ -59,9 +59,7 @@ func (ss *SearchService) Search(ctx context.Context, dto *schema.SearchDTO) (res
func (ss *SearchService) searchByPlugin(ctx context.Context, finder plugin.Search, cond *schema.SearchCondition, dto *schema.SearchDTO) (resp *schema.SearchResp, err error) {
var res []plugin.SearchResult
- resp = &schema.SearchResp{
- SearchPluginIcon: finder.Description().Icon,
- }
+ resp = &schema.SearchResp{}
if cond.SearchAll() {
res, resp.Total, err = finder.SearchContents(ctx, cond.Convert2PluginSearchCond(dto.Page, dto.Size, dto.Order))
} else if cond.SearchQuestion() {