Skip to content

Commit 6e57576

Browse files
committed
fix(matching-service): 🚑 fix some issues with matching algorithm
Fix the matched difficulties and topics so that it will be an OR if either is empty. Also fixes an issue with difficulties matching using wrong variable topics.
1 parent f01ba09 commit 6e57576

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

apps/matching-service/processes/findmatches.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,38 @@ func foundMatch(tx *redis.Tx, ctx context.Context, currentUser *models.MatchRequ
7474
}
7575

7676
var matchedTopics []string
77-
for _, topic := range currentUser.Topics {
77+
if len(currentUser.Topics) == 0 || len(currentUser.Topics) == 0 {
78+
// Ensure that matchedTopics will not be empty unless both users are empty
79+
for _, topic := range currentUser.Topics {
80+
matchedTopics = append(matchedTopics, topic)
81+
}
7882
for _, otherTopic := range matchedUser.Topics {
79-
if topic == otherTopic {
80-
matchedTopics = append(matchedTopics, topic)
83+
matchedTopics = append(matchedTopics, otherTopic)
84+
}
85+
} else {
86+
for _, topic := range currentUser.Topics {
87+
for _, otherTopic := range matchedUser.Topics {
88+
if topic == otherTopic {
89+
matchedTopics = append(matchedTopics, topic)
90+
}
8191
}
8292
}
8393
}
8494
var matchedDifficulties []string
85-
for _, topic := range currentUser.Difficulties {
86-
for _, otherTopic := range matchedUser.Difficulties {
87-
if topic == otherTopic {
88-
matchedDifficulties = append(matchedDifficulties, topic)
95+
if len(currentUser.Difficulties) == 0 || len(currentUser.Difficulties) == 0 {
96+
// Ensure that matchedDifficulties will not be empty unless both users are empty
97+
for _, diff := range currentUser.Difficulties {
98+
matchedDifficulties = append(matchedDifficulties, diff)
99+
}
100+
for _, otherDiff := range matchedUser.Difficulties {
101+
matchedDifficulties = append(matchedDifficulties, otherDiff)
102+
}
103+
} else {
104+
for _, diff := range currentUser.Difficulties {
105+
for _, otherDiff := range matchedUser.Difficulties {
106+
if diff == otherDiff {
107+
matchedDifficulties = append(matchedDifficulties, diff)
108+
}
89109
}
90110
}
91111
}
@@ -200,7 +220,7 @@ func doDifficultyMatching(tx *redis.Tx, ctx context.Context, currentUser *models
200220
if err != nil {
201221
return nil, err
202222
}
203-
if len(otherUser.Topics) == 0 {
223+
if len(otherUser.Difficulties) == 0 {
204224
foundUsers = append(foundUsers, otherUsername)
205225
}
206226

0 commit comments

Comments
 (0)