Skip to content

Commit

Permalink
fix(matching-service): 🚑 fix some issues with matching algorithm
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tituschewxj committed Nov 13, 2024
1 parent f01ba09 commit 6e57576
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions apps/matching-service/processes/findmatches.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,38 @@ func foundMatch(tx *redis.Tx, ctx context.Context, currentUser *models.MatchRequ
}

var matchedTopics []string
for _, topic := range currentUser.Topics {
if len(currentUser.Topics) == 0 || len(currentUser.Topics) == 0 {
// Ensure that matchedTopics will not be empty unless both users are empty
for _, topic := range currentUser.Topics {
matchedTopics = append(matchedTopics, topic)
}
for _, otherTopic := range matchedUser.Topics {
if topic == otherTopic {
matchedTopics = append(matchedTopics, topic)
matchedTopics = append(matchedTopics, otherTopic)
}
} else {
for _, topic := range currentUser.Topics {
for _, otherTopic := range matchedUser.Topics {
if topic == otherTopic {
matchedTopics = append(matchedTopics, topic)
}
}
}
}
var matchedDifficulties []string
for _, topic := range currentUser.Difficulties {
for _, otherTopic := range matchedUser.Difficulties {
if topic == otherTopic {
matchedDifficulties = append(matchedDifficulties, topic)
if len(currentUser.Difficulties) == 0 || len(currentUser.Difficulties) == 0 {
// Ensure that matchedDifficulties will not be empty unless both users are empty
for _, diff := range currentUser.Difficulties {
matchedDifficulties = append(matchedDifficulties, diff)
}
for _, otherDiff := range matchedUser.Difficulties {
matchedDifficulties = append(matchedDifficulties, otherDiff)
}
} else {
for _, diff := range currentUser.Difficulties {
for _, otherDiff := range matchedUser.Difficulties {
if diff == otherDiff {
matchedDifficulties = append(matchedDifficulties, diff)
}
}
}
}
Expand Down Expand Up @@ -200,7 +220,7 @@ func doDifficultyMatching(tx *redis.Tx, ctx context.Context, currentUser *models
if err != nil {
return nil, err
}
if len(otherUser.Topics) == 0 {
if len(otherUser.Difficulties) == 0 {
foundUsers = append(foundUsers, otherUsername)
}

Expand Down

0 comments on commit 6e57576

Please sign in to comment.