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.
feat(plugin): update search condition
LinkinStarsbf50c8971c08
diff --git a/internal/repo/answer/answer_repo.go b/internal/repo/answer/answer_repo.goindex 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 erType: 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.goindex 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) (erType: 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.goindex 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 strWords: 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.goindex 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 stringconst (- AcceptedCondAll AcceptedCond = iota+ AcceptedCondAll SearchAcceptedCond = iotaAcceptedCondTrueAcceptedCondFalse)+const (+ SearchContentStatusAvailable = 1+ SearchContentStatusDeleted = 10+)++const (+ SearchNewestOrder SearchOrderCond = "newest"+ SearchActiveOrder SearchOrderCond = "active"+ SearchScoreOrder SearchOrderCond = "score"+ SearchRelevanceOrder SearchOrderCond = "relevance"+)+type Search interface {BaseSearchContents(ctx context.Context, cond *SearchBasicCond) (res []SearchResult, total int64, err error)