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.goindex 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.jsonindex 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.yamlindex 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: objecthandler.RespBody:properties:code:@@ -95,6 +88,8 @@ definitions:type: stringdisplay_name:type: string+ main_tag_slug_name:+ type: stringobject_type:type: stringquestion_id:@@ -179,6 +174,13 @@ definitions:- object_id- report_typetype: object+ schema.AdminSetAnswerStatusRequest:+ properties:+ answer_id:+ type: string+ status:+ type: string+ type: objectschema.AdminSetQuestionStatusRequest:properties:question_id:@@ -203,7 +205,6 @@ definitions:answer_id:type: stringquestion_id:- description: question_idtype: stringtype: objectschema.AnswerUpdateReq:@@ -1722,7 +1723,7 @@ paths:name: datarequired: trueschema:- $ref: '#/definitions/entity.AdminSetAnswerStatusRequest'+ $ref: '#/definitions/schema.AdminSetAnswerStatusRequest'produces:- application/jsonresponses:diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.goindex 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.RespBodyfunc (ac *AnswerController) AdminSetAnswerStatus(ctx *gin.Context) {diff --git a/internal/repo/search_common/search_repo.go b/internal/repo/search_common/search_repo.goindex 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 datafunc (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.Builderub *builder.Builder@@ -80,9 +79,14 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagIDsargsQ = []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.goindex 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) (userIDre := 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.IDq = re.ReplaceAllString(q, "")}- } else if strings.Index(q, exprMe) != -1 {- userID = currentUserID- q = strings.ReplaceAll(q, exprMe, "")}*query = strings.TrimSpace(q)returndiff --git a/internal/service/search_service.go b/internal/service/search_service.goindex 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 typesearchType,- // search all+ // search alluserID,votes,- // search questions+ // search questionsnotAccepted,_,views,answers,- // search answers+ // search answersaccepted,questionID,_,- // common fields+ // common fieldstags,words := ss.searchParser.ParseStructure(dto)