ParseStructure parse search structure, maybe match one of type all/questions/answers, but if match two type, it will return false
(ctx context.Context, dto *schema.SearchDTO)
| 48 | // ParseStructure parse search structure, maybe match one of type all/questions/answers, |
| 49 | // but if match two type, it will return false |
| 50 | func (sp *SearchParser) ParseStructure(ctx context.Context, dto *schema.SearchDTO) (cond *schema.SearchCondition) { |
| 51 | cond = &schema.SearchCondition{} |
| 52 | var ( |
| 53 | query = dto.Query |
| 54 | limitWords = 5 |
| 55 | ) |
| 56 | |
| 57 | // match tags |
| 58 | cond.Tags = sp.parseTags(ctx, &query) |
| 59 | |
| 60 | // match all |
| 61 | cond.UserID = sp.parseUserID(ctx, &query, dto.UserID) |
| 62 | cond.VoteAmount = sp.parseVotes(&query) |
| 63 | cond.Words = sp.parseWithin(&query) |
| 64 | |
| 65 | // match questions |
| 66 | cond.NotAccepted = sp.parseNotAccepted(&query) |
| 67 | if cond.NotAccepted { |
| 68 | cond.TargetType = constant.QuestionObjectType |
| 69 | } |
| 70 | cond.Views = sp.parseViews(&query) |
| 71 | if cond.Views != -1 { |
| 72 | cond.TargetType = constant.QuestionObjectType |
| 73 | } |
| 74 | cond.AnswerAmount = sp.parseAnswers(&query) |
| 75 | if cond.AnswerAmount != -1 { |
| 76 | cond.TargetType = constant.QuestionObjectType |
| 77 | } |
| 78 | |
| 79 | // match answers |
| 80 | cond.Accepted = sp.parseAccepted(&query) |
| 81 | if cond.Accepted { |
| 82 | cond.TargetType = constant.AnswerObjectType |
| 83 | } |
| 84 | cond.QuestionID = sp.parseQuestionID(&query) |
| 85 | if cond.QuestionID != "" { |
| 86 | cond.TargetType = constant.AnswerObjectType |
| 87 | } |
| 88 | |
| 89 | if sp.parseIsQuestion(&query) { |
| 90 | cond.TargetType = constant.QuestionObjectType |
| 91 | } |
| 92 | if sp.parseIsAnswer(&query) { |
| 93 | cond.TargetType = constant.AnswerObjectType |
| 94 | } |
| 95 | |
| 96 | if len(strings.TrimSpace(query)) > 0 { |
| 97 | words := strings.Split(strings.TrimSpace(query), " ") |
| 98 | cond.Words = append(cond.Words, words...) |
| 99 | } |
| 100 | |
| 101 | // check limit words |
| 102 | if len(cond.Words) > limitWords { |
| 103 | cond.Words = cond.Words[:limitWords] |
| 104 | } |
| 105 | return |
| 106 | } |
| 107 |
no test coverage detected