Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: matching algorithm #89

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(matchedUser.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(matchedUser.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
Loading