Skip to content

Commit 51d38b4

Browse files
xdefragclaude
andcommitted
fix: prioritize membership level in reputation search sorting
When sorting search results by reputation, now first sorts by MTLAP/MTLAC balance (membership level) descending, then by reputation grade and weight. This ensures higher-level Association members appear at the top, with reputation as a secondary sort criterion. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ee4b60e commit 51d38b4

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

internal/repository/account.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -561,17 +561,21 @@ func (r *AccountRepository) SearchAccounts(ctx context.Context, query string, ta
561561
// Apply sorting
562562
switch sortBy {
563563
case SearchSortByReputation:
564-
// Sort by grade bucket first (A=1, A-=2, B+=3, etc), then by weight within grade
565-
qb = qb.OrderBy(`CASE
566-
WHEN COALESCE(rs.weighted_score, 0) >= 3.5 THEN 1
567-
WHEN COALESCE(rs.weighted_score, 0) >= 3.0 THEN 2
568-
WHEN COALESCE(rs.weighted_score, 0) >= 2.5 THEN 3
569-
WHEN COALESCE(rs.weighted_score, 0) >= 2.0 THEN 4
570-
WHEN COALESCE(rs.weighted_score, 0) >= 1.5 THEN 5
571-
WHEN COALESCE(rs.weighted_score, 0) >= 1.0 THEN 6
572-
WHEN COALESCE(rs.weighted_score, 0) > 0 THEN 7
573-
ELSE 8
574-
END ASC`, "COALESCE(rs.total_weight, 0) DESC")
564+
// Sort by membership level first (MTLAP/MTLAC balance), then by grade bucket, then by weight
565+
qb = qb.OrderBy(
566+
"GREATEST(a.mtlap_balance, a.mtlac_balance) DESC",
567+
`CASE
568+
WHEN COALESCE(rs.weighted_score, 0) >= 3.5 THEN 1
569+
WHEN COALESCE(rs.weighted_score, 0) >= 3.0 THEN 2
570+
WHEN COALESCE(rs.weighted_score, 0) >= 2.5 THEN 3
571+
WHEN COALESCE(rs.weighted_score, 0) >= 2.0 THEN 4
572+
WHEN COALESCE(rs.weighted_score, 0) >= 1.5 THEN 5
573+
WHEN COALESCE(rs.weighted_score, 0) >= 1.0 THEN 6
574+
WHEN COALESCE(rs.weighted_score, 0) > 0 THEN 7
575+
ELSE 8
576+
END ASC`,
577+
"COALESCE(rs.total_weight, 0) DESC",
578+
)
575579
default: // SearchSortByBalance
576580
qb = qb.OrderBy("GREATEST(a.mtlap_balance, a.mtlac_balance) DESC", "a.total_xlm_value DESC")
577581
}

0 commit comments

Comments
 (0)