(ctx context.Context, expression string)
| 44 | return comments, nil |
| 45 | } |
| 46 | func (s *searchService) SearchPosts(ctx context.Context, expression string) ([]domain.PostSearch, error) { |
| 47 | // 将表达式拆分为关键字数组 |
| 48 | keywords := strings.Split(expression, " ") |
| 49 | |
| 50 | var eg errgroup.Group |
| 51 | var posts []domain.PostSearch |
| 52 | |
| 53 | eg.Go(func() error { |
| 54 | // 搜索帖子 |
| 55 | foundPosts, err := s.repo.SearchPosts(ctx, keywords) |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | |
| 60 | posts = foundPosts |
| 61 | |
| 62 | return nil |
| 63 | }) |
| 64 | |
| 65 | // 等待所有并发任务完成 |
| 66 | if err := eg.Wait(); err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | |
| 70 | return posts, nil |
| 71 | } |
| 72 | |
| 73 | func (s *searchService) SearchUsers(ctx context.Context, expression string) ([]domain.UserSearch, error) { |
| 74 | // 将表达式拆分为关键字数组 |
nothing calls this directly
no test coverage detected