MCPcopy Index your code
hub / github.com/apache/answer / Search

Method Search

internal/service/content/search_service.go:47–85  ·  view source on GitHub ↗

Search search contents

(ctx context.Context, dto *schema.SearchDTO)

Source from the content-addressed store, hash-verified

45
46// Search search contents
47func (ss *SearchService) Search(ctx context.Context, dto *schema.SearchDTO) (resp *schema.SearchResp, err error) {
48 if dto.Page < 1 {
49 dto.Page = 1
50 }
51 if len(dto.Query) == 0 {
52 return &schema.SearchResp{
53 Total: 0,
54 SearchResults: make([]*schema.SearchResult, 0),
55 }, nil
56 }
57
58 // search type
59 cond := ss.searchParser.ParseStructure(ctx, dto)
60
61 // check search plugin
62 var finder plugin.Search
63 _ = plugin.CallSearch(func(search plugin.Search) error {
64 finder = search
65 return nil
66 })
67
68 resp = &schema.SearchResp{}
69 // search plugin is not found, call system search
70 if finder == nil {
71 switch {
72 case cond.SearchAll():
73 resp.SearchResults, resp.Total, err =
74 ss.searchRepo.SearchContents(ctx, cond.Words, cond.Tags, cond.UserID, cond.VoteAmount, dto.Page, dto.Size, dto.Order)
75 case cond.SearchQuestion():
76 resp.SearchResults, resp.Total, err =
77 ss.searchRepo.SearchQuestions(ctx, cond.Words, cond.Tags, cond.NotAccepted, cond.Views, cond.AnswerAmount, dto.Page, dto.Size, dto.Order)
78 case cond.SearchAnswer():
79 resp.SearchResults, resp.Total, err =
80 ss.searchRepo.SearchAnswers(ctx, cond.Words, cond.Tags, cond.Accepted, cond.QuestionID, dto.Page, dto.Size, dto.Order)
81 }
82 return
83 }
84 return ss.searchByPlugin(ctx, finder, cond, dto)
85}
86
87func (ss *SearchService) searchByPlugin(ctx context.Context, finder plugin.Search, cond *schema.SearchCondition, dto *schema.SearchDTO) (resp *schema.SearchResp, err error) {
88 var res []plugin.SearchResult

Callers 2

RemoveQuestionMethod · 0.45
SearchUserTopListMethod · 0.45

Calls 8

searchByPluginMethod · 0.95
ParseStructureMethod · 0.80
SearchAllMethod · 0.80
SearchQuestionMethod · 0.80
SearchAnswerMethod · 0.80
SearchContentsMethod · 0.65
SearchQuestionsMethod · 0.65
SearchAnswersMethod · 0.65

Tested by

no test coverage detected