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(search): user:me or user:username can be searched

kumfo9170a801f654
diff --git a/docs/docs.go b/docs/docs.go
index 21f184bc..8be35387 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -105,7 +105,7 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
- "$ref": "#/definitions/entity.AdminSetAnswerStatusRequest"
+ "$ref": "#/definitions/schema.AdminSetAnswerStatusRequest"
}
}
],
@@ -4595,17 +4595,6 @@ const docTemplate = `{
}
},
"definitions": {
- "entity.AdminSetAnswerStatusRequest": {
- "type": "object",
- "properties": {
- "answer_id": {
- "type": "string"
- },
- "status": {
- "type": "string"
- }
- }
- },
"handler.RespBody": {
"type": "object",
"properties": {
@@ -4732,6 +4721,9 @@ const docTemplate = `{
"display_name": {
"type": "string"
},
+ "main_tag_slug_name": {
+ "type": "string"
+ },
"object_type": {
"type": "string"
},
@@ -4854,6 +4846,17 @@ const docTemplate = `{
}
}
},
+ "schema.AdminSetAnswerStatusRequest": {
+ "type": "object",
+ "properties": {
+ "answer_id": {
+ "type": "string"
+ },
+ "status": {
+ "type": "string"
+ }
+ }
+ },
"schema.AdminSetQuestionStatusRequest": {
"type": "object",
"properties": {
@@ -4889,7 +4892,6 @@ const docTemplate = `{
"type": "string"
},
"question_id": {
- "description": "question_id",
"type": "string"
}
}
diff --git a/docs/swagger.json b/docs/swagger.json
index 05fdf0af..e9361561 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -93,7 +93,7 @@
"in": "body",
"required": true,
"schema": {
- "$ref": "#/definitions/entity.AdminSetAnswerStatusRequest"
+ "$ref": "#/definitions/schema.AdminSetAnswerStatusRequest"
}
}
],
@@ -4583,17 +4583,6 @@
}
},
"definitions": {
- "entity.AdminSetAnswerStatusRequest": {
- "type": "object",
- "properties": {
- "answer_id": {
- "type": "string"
- },
- "status": {
- "type": "string"
- }
- }
- },
"handler.RespBody": {
"type": "object",
"properties": {
@@ -4720,6 +4709,9 @@
"display_name": {
"type": "string"
},
+ "main_tag_slug_name": {
+ "type": "string"
+ },
"object_type": {
"type": "string"
},
@@ -4842,6 +4834,17 @@
}
}
},
+ "schema.AdminSetAnswerStatusRequest": {
+ "type": "object",
+ "properties": {
+ "answer_id": {
+ "type": "string"
+ },
+ "status": {
+ "type": "string"
+ }
+ }
+ },
"schema.AdminSetQuestionStatusRequest": {
"type": "object",
"properties": {
@@ -4877,7 +4880,6 @@
"type": "string"
},
"question_id": {
- "description": "question_id",
"type": "string"
}
}
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index ae9e1bf8..8d456b5b 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1,11 +1,4 @@
definitions:
- entity.AdminSetAnswerStatusRequest:
- properties:
- answer_id:
- type: string
- status:
- type: string
- type: object
handler.RespBody:
properties:
code:
@@ -95,6 +88,8 @@ definitions:
type: string
display_name:
type: string
+ main_tag_slug_name:
+ type: string
object_type:
type: string
question_id:
@@ -179,6 +174,13 @@ definitions:
- object_id
- report_type
type: object
+ schema.AdminSetAnswerStatusRequest:
+ properties:
+ answer_id:
+ type: string
+ status:
+ type: string
+ type: object
schema.AdminSetQuestionStatusRequest:
properties:
question_id:
@@ -203,7 +205,6 @@ definitions:
answer_id:
type: string
question_id:
- description: question_id
type: string
type: object
schema.AnswerUpdateReq:
@@ -1722,7 +1723,7 @@ paths:
name: data
required: true
schema:
- $ref: '#/definitions/entity.AdminSetAnswerStatusRequest'
+ $ref: '#/definitions/schema.AdminSetAnswerStatusRequest'
produces:
- application/json
responses:
diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.go
index 2b91d779..e1b3ca71 100644
--- a/internal/controller/answer_controller.go
+++ b/internal/controller/answer_controller.go
@@ -267,7 +267,7 @@ func (ac *AnswerController) Adopted(ctx *gin.Context) {
// @Accept json
// @Produce json
// @Security ApiKeyAuth
-// @Param data body entity.AdminSetAnswerStatusRequest true "AdminSetAnswerStatusRequest"
+// @Param data body schema.AdminSetAnswerStatusRequest true "AdminSetAnswerStatusRequest"
// @Router /answer/admin/api/answer/status [put]
// @Success 200 {object} handler.RespBody
func (ac *AnswerController) AdminSetAnswerStatus(ctx *gin.Context) {
diff --git a/internal/repo/search_common/search_repo.go b/internal/repo/search_common/search_repo.go
index 666ba4fd..5c5bc25f 100644
--- a/internal/repo/search_common/search_repo.go
+++ b/internal/repo/search_common/search_repo.go
@@ -69,9 +69,8 @@ func NewSearchRepo(data *data.Data, uniqueIDRepo unique.UniqueIDRepo, userCommon
// SearchContents search question and answer data
func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagIDs []string, userID string, votes int, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {
- if words = filterWords(words); len(words) == 0 {
- return
- }
+ words = filterWords(words)
+
var (
b *builder.Builder
ub *builder.Builder
@@ -80,9 +79,14 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagIDs
argsQ = []interface{}{}
argsA = []interface{}{}
)
+
if order == "relevance" {
- qfs, argsQ = addRelevanceField([]string{"title", "original_text"}, words, qfs)
- afs, argsA = addRelevanceField([]string{"`answer`.`original_text`"}, words, afs)
+ if len(words) > 0 {
+ qfs, argsQ = addRelevanceField([]string{"title", "original_text"}, words, qfs)
+ afs, argsA = addRelevanceField([]string{"`answer`.`original_text`"}, words, afs)
+ } else {
+ order = "newest"
+ }
}
b = builder.MySQL().Select(qfs...).From("`question`")
diff --git a/internal/service/search_parser/search_parser.go b/internal/service/search_parser/search_parser.go
index 3fbbba56..a34baecf 100644
--- a/internal/service/search_parser/search_parser.go
+++ b/internal/service/search_parser/search_parser.go
@@ -189,16 +189,16 @@ func (sp *SearchParser) parseUserID(query *string, currentUserID string) (userID
re := regexp.MustCompile(exprUserID)
res := re.FindStringSubmatch(q)
- if len(res) == 2 {
+ if strings.Index(q, exprMe) != -1 {
+ userID = currentUserID
+ q = strings.ReplaceAll(q, exprMe, "")
+ } else if len(res) == 2 {
name := res[1]
user, has, err := sp.userCommon.GetUserBasicInfoByUserName(nil, name)
if err == nil && has {
userID = user.ID
q = re.ReplaceAllString(q, "")
}
- } else if strings.Index(q, exprMe) != -1 {
- userID = currentUserID
- q = strings.ReplaceAll(q, exprMe, "")
}
*query = strings.TrimSpace(q)
return
diff --git a/internal/service/search_service.go b/internal/service/search_service.go
index 33d3f51e..61b622fb 100644
--- a/internal/service/search_service.go
+++ b/internal/service/search_service.go
@@ -31,19 +31,19 @@ func (ss *SearchService) Search(ctx context.Context, dto *schema.SearchDTO) (res
// search type
searchType,
- // search all
+ // search all
userID,
votes,
- // search questions
+ // search questions
notAccepted,
_,
views,
answers,
- // search answers
+ // search answers
accepted,
questionID,
_,
- // common fields
+ // common fields
tags,
words := ss.searchParser.ParseStructure(dto)