From bf50c8971c08f9e8884edd57fd339afe29685bac Mon Sep 17 00:00:00 2001 From: LinkinStars Date: Wed, 26 Jul 2023 16:35:33 +0800 Subject: [PATCH] feat(plugin): update search condition --- internal/repo/answer/answer_repo.go | 2 +- internal/repo/question/question_repo.go | 2 +- internal/schema/search_schema.go | 2 +- plugin/search.go | 52 ++++++++++++++++--------- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/internal/repo/answer/answer_repo.go b/internal/repo/answer/answer_repo.go index f6a2ff1a..2cffdb4a 100644 --- a/internal/repo/answer/answer_repo.go +++ b/internal/repo/answer/answer_repo.go @@ -381,7 +381,7 @@ func (ar *answerRepo) updateSearch(ctx context.Context, answerID string) (err er Type: constant.AnswerObjectType, Content: answer.ParsedText, Answers: 0, - Status: int64(answer.Status), + Status: plugin.SearchContentStatus(answer.Status), Tags: tags, QuestionID: answer.QuestionID, UserID: answer.UserID, diff --git a/internal/repo/question/question_repo.go b/internal/repo/question/question_repo.go index 19324eb4..eb159628 100644 --- a/internal/repo/question/question_repo.go +++ b/internal/repo/question/question_repo.go @@ -457,7 +457,7 @@ func (qr *questionRepo) updateSearch(ctx context.Context, questionID string) (er Type: constant.QuestionObjectType, Content: question.ParsedText, Answers: int64(question.AnswerCount), - Status: int64(question.Status), + Status: plugin.SearchContentStatus(question.Status), Tags: tags, QuestionID: questionID, UserID: question.UserID, diff --git a/internal/schema/search_schema.go b/internal/schema/search_schema.go index 95b578c2..4e51d85a 100644 --- a/internal/schema/search_schema.go +++ b/internal/schema/search_schema.go @@ -59,7 +59,7 @@ func (s *SearchCondition) Convert2PluginSearchCond(page, pageSize int, order str Words: s.Words, TagIDs: s.Tags, UserID: s.UserID, - Order: order, + Order: plugin.SearchOrderCond(order), QuestionID: s.QuestionID, VoteAmount: s.VoteAmount, ViewAmount: s.Views, diff --git a/plugin/search.go b/plugin/search.go index 42b303b5..4d9d1921 100644 --- a/plugin/search.go +++ b/plugin/search.go @@ -12,20 +12,20 @@ type SearchResult struct { } type SearchContent struct { - ObjectID string `json:"objectID"` - Title string `json:"title"` - Type string `json:"type"` - Content string `json:"content"` - Answers int64 `json:"answers"` - Status int64 `json:"status"` - Tags []string `json:"tags"` - QuestionID string `json:"questionID"` - UserID string `json:"userID"` - Views int64 `json:"views"` - Created int64 `json:"created"` - Active int64 `json:"active"` - Score int64 `json:"score"` - HasAccepted bool `json:"hasAccepted"` + ObjectID string `json:"objectID"` + Title string `json:"title"` + Type string `json:"type"` + Content string `json:"content"` + Answers int64 `json:"answers"` + Status SearchContentStatus `json:"status"` + Tags []string `json:"tags"` + QuestionID string `json:"questionID"` + UserID string `json:"userID"` + Views int64 `json:"views"` + Created int64 `json:"created"` + Active int64 `json:"active"` + Score int64 `json:"score"` + HasAccepted bool `json:"hasAccepted"` } type SearchBasicCond struct { @@ -41,12 +41,12 @@ type SearchBasicCond struct { // The object's owner user ID. UserID string // The order of the search result. - Order string + Order SearchOrderCond // Weathers the question is accepted or not. Only support search question. - QuestionAccepted AcceptedCond + QuestionAccepted SearchAcceptedCond // Weathers the answer is accepted or not. Only support search answer. - AnswerAccepted AcceptedCond + AnswerAccepted SearchAcceptedCond // Only support search answer. QuestionID string @@ -59,14 +59,28 @@ type SearchBasicCond struct { AnswerAmount int } -type AcceptedCond int +type SearchAcceptedCond int +type SearchContentStatus int +type SearchOrderCond string const ( - AcceptedCondAll AcceptedCond = iota + AcceptedCondAll SearchAcceptedCond = iota AcceptedCondTrue AcceptedCondFalse ) +const ( + SearchContentStatusAvailable = 1 + SearchContentStatusDeleted = 10 +) + +const ( + SearchNewestOrder SearchOrderCond = "newest" + SearchActiveOrder SearchOrderCond = "active" + SearchScoreOrder SearchOrderCond = "score" + SearchRelevanceOrder SearchOrderCond = "relevance" +) + type Search interface { Base SearchContents(ctx context.Context, cond *SearchBasicCond) (res []SearchResult, total int64, err error)