feat(plugin): update search condition

This commit is contained in:
LinkinStars 2023-07-26 16:35:33 +08:00
parent 5a03fef6ec
commit bf50c8971c
4 changed files with 36 additions and 22 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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)