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.

fix question tags search

aichy126c3b096edc59d
diff --git a/docs/docs.go b/docs/docs.go
index 51596b91..e7df3ce0 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -4961,12 +4961,9 @@ const docTemplate = `{
"description": "Search page size",
"type": "integer"
},
- "tags": {
- "description": "Search tag",
- "type": "array",
- "items": {
- "type": "string"
- }
+ "tag": {
+ "description": "Tags []string ` + "`" + `json:\"tags\" form:\"tags\"` + "`" + ` //Search tag",
+ "type": "string"
},
"username": {
"description": "Search username",
diff --git a/docs/swagger.json b/docs/swagger.json
index bd08e554..1063944b 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -4949,12 +4949,9 @@
"description": "Search page size",
"type": "integer"
},
- "tags": {
- "description": "Search tag",
- "type": "array",
- "items": {
- "type": "string"
- }
+ "tag": {
+ "description": "Tags []string `json:\"tags\" form:\"tags\"` //Search tag",
+ "type": "string"
},
"username": {
"description": "Search username",
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index cf6bcd49..bde9a77d 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -762,11 +762,10 @@ definitions:
page_size:
description: Search page size
type: integer
- tags:
- description: Search tag
- items:
- type: string
- type: array
+ tag:
+ description: Tags []string `json:"tags" form:"tags"` //Search
+ tag
+ type: string
username:
description: Search username
type: string
diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.go
index a619c454..5bd3b4c1 100644
--- a/internal/schema/question_schema.go
+++ b/internal/schema/question_schema.go
@@ -156,12 +156,13 @@ type UserQuestionInfo struct {
}
type QuestionSearch struct {
- Page int `json:"page" form:"page"` //Query number of pages
- PageSize int `json:"page_size" form:"page_size"` //Search page size
- Order string `json:"order" form:"order"` //Search order by
- Tags []string `json:"tags" form:"tags"` //Search tag
- TagIDs []string `json:"-" form:"-"` //Search tag
- UserName string `json:"username" form:"username"` //Search username
+ Page int `json:"page" form:"page"` //Query number of pages
+ PageSize int `json:"page_size" form:"page_size"` //Search page size
+ Order string `json:"order" form:"order"` //Search order by
+ //Tags []string `json:"tags" form:"tags"` //Search tag
+ Tag string `json:"tag" form:"tag"` //Search tag
+ TagIDs []string `json:"-" form:"-"` //Search tag
+ UserName string `json:"username" form:"username"` //Search username
UserID string `json:"-" form:"-"`
}
diff --git a/internal/service/question_service.go b/internal/service/question_service.go
index 88178654..8aa59898 100644
--- a/internal/service/question_service.go
+++ b/internal/service/question_service.go
@@ -481,20 +481,23 @@ func (qs *QuestionService) SimilarQuestion(ctx context.Context, questionID strin
search.Order = "frequent"
search.Page = 0
search.PageSize = 6
- search.Tags = tagNames
+ if len(tagNames) > 0 {
+ search.Tag = tagNames[0]
+ }
return qs.SearchList(ctx, search, loginUserID)
}
// SearchList
func (qs *QuestionService) SearchList(ctx context.Context, req *schema.QuestionSearch, loginUserID string) ([]*schema.QuestionInfo, int64, error) {
- if len(req.Tags) > 0 {
- taginfo, err := qs.tagCommon.GetTagListByNames(ctx, req.Tags)
+ if len(req.Tag) > 0 {
+ taginfo, has, err := qs.tagCommon.GetTagListByName(ctx, req.Tag)
if err != nil {
log.Error("tagCommon.GetTagListByNames error", err)
}
- for _, tag := range taginfo {
- req.TagIDs = append(req.TagIDs, tag.ID)
+ if has {
+ req.TagIDs = append(req.TagIDs, taginfo.ID)
}
+
}
list := make([]*schema.QuestionInfo, 0)
if req.UserName != "" {