mirror of https://gitee.com/answerdev/answer.git
fix(search): user:me or user:username can be searched
This commit is contained in:
parent
24641e5cf0
commit
9170a801f6
28
docs/docs.go
28
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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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`")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue