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

Method SimilarQuestion

internal/service/content/question_service.go:1439–1467  ·  view source on GitHub ↗

SimilarQuestion

(ctx context.Context, questionID string, loginUserID string)

Source from the content-addressed store, hash-verified

1437
1438// SimilarQuestion
1439func (qs *QuestionService) SimilarQuestion(ctx context.Context, questionID string, loginUserID string) ([]*schema.QuestionPageResp, int64, error) {
1440 question, err := qs.questioncommon.Info(ctx, questionID, loginUserID)
1441 if err != nil {
1442 return nil, 0, nil
1443 }
1444 tagNames := make([]string, 0, len(question.Tags))
1445 for _, tag := range question.Tags {
1446 tagNames = append(tagNames, tag.SlugName)
1447 }
1448 search := &schema.QuestionPageReq{}
1449 search.OrderCond = "hot"
1450 search.Page = 0
1451 search.PageSize = 6
1452 if len(tagNames) > 0 {
1453 search.Tag = tagNames[0]
1454 }
1455 search.LoginUserID = loginUserID
1456 similarQuestions, _, err := qs.GetQuestionPage(ctx, search)
1457 if err != nil {
1458 return nil, 0, err
1459 }
1460 var result []*schema.QuestionPageResp
1461 for _, v := range similarQuestions {
1462 if uid.DeShortID(v.ID) != questionID {
1463 result = append(result, v)
1464 }
1465 }
1466 return result, int64(len(result)), nil
1467}
1468
1469// GetQuestionPage query questions page
1470func (qs *QuestionService) GetQuestionPage(ctx context.Context, req *schema.QuestionPageReq) (

Callers

nothing calls this directly

Calls 3

GetQuestionPageMethod · 0.95
DeShortIDFunction · 0.92
InfoMethod · 0.65

Tested by

no test coverage detected