From 893024c23917c7ee550d75063073ab0eae47313e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 01:38:17 +0000 Subject: [PATCH 1/2] Initial plan From 0c2e1a3fbd1a2600fe135182a6dd0009f0bfe125 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 01:46:09 +0000 Subject: [PATCH 2/2] Fix name sorting by splitting on symbols instead of removing them Change IntelligentKnownName tokenizer to replace punctuation with spaces instead of removing them. This creates token boundaries at symbol positions, fixing sorting of names like "15-9" vs "15-10" which were previously being compared as single numbers (159 vs 1510). Fixes issue where hyphenated numbers like 15-10 appeared after 20-4 instead of after 15-9. Co-authored-by: OxygenCobalt <65370175+OxygenCobalt@users.noreply.github.com> --- .../oxycblt/musikr/tag/interpret/Naming.kt | 8 ++--- .../musikr/tag/interpret/NamingTest.kt | 30 +++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/musikr/src/main/java/org/oxycblt/musikr/tag/interpret/Naming.kt b/musikr/src/main/java/org/oxycblt/musikr/tag/interpret/Naming.kt index caa620efd..8f42ec171 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/tag/interpret/Naming.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/tag/interpret/Naming.kt @@ -86,10 +86,10 @@ private data class IntelligentKnownName(override val raw: String, override val s // optimize it val stripped = name - // Remove excess punctuation from the string, as those usually aren't - // considered in sorting. - .replace(punctRegex, "") - .ifEmpty { name } + // Replace punctuation with spaces to create token boundaries, improving + // sorting of names like "15-9" vs "15-10". + .replace(punctRegex, " ") + .let { if (it.isBlank()) name else it } .run { // Strip any english articles like "the" or "an" from the start, as music // sorting should ignore such when possible. diff --git a/musikr/src/test/java/org/oxycblt/musikr/tag/interpret/NamingTest.kt b/musikr/src/test/java/org/oxycblt/musikr/tag/interpret/NamingTest.kt index d52d3f0e3..904e21e68 100644 --- a/musikr/src/test/java/org/oxycblt/musikr/tag/interpret/NamingTest.kt +++ b/musikr/src/test/java/org/oxycblt/musikr/tag/interpret/NamingTest.kt @@ -212,7 +212,8 @@ class NamingTest { assertEquals("alt-J", name.raw) assertEquals(null, name.sort) val only = name.tokens.single() - assertEquals("altJ", only.collationKey.sourceString) + // Punctuation is replaced with spaces to create token boundaries + assertEquals("alt J", only.collationKey.sourceString) assertEquals(Token.Type.LEXICOGRAPHIC, only.type) } @@ -242,7 +243,8 @@ class NamingTest { assertEquals("& Yet & Yet", name.raw) assertEquals(null, name.sort) val first = name.tokens[0] - assertEquals("Yet Yet", first.collationKey.sourceString) + // Punctuation is replaced with spaces, so each & becomes a space + assertEquals("Yet Yet", first.collationKey.sourceString) assertEquals(Token.Type.LEXICOGRAPHIC, first.type) } @@ -258,7 +260,8 @@ class NamingTest { assertEquals("2", second.collationKey.sourceString) assertEquals(Token.Type.NUMERIC, second.type) val third = name.tokens[2] - assertEquals(" ", third.collationKey.sourceString) + // Punctuation is replaced with spaces, so : becomes a space + assertEquals(" ", third.collationKey.sourceString) assertEquals(Token.Type.LEXICOGRAPHIC, third.type) val fourth = name.tokens[3] assertEquals("3", fourth.collationKey.sourceString) @@ -274,13 +277,15 @@ class NamingTest { assertEquals("2", first.collationKey.sourceString) assertEquals(Token.Type.NUMERIC, first.type) val second = name.tokens[1] - assertEquals(" ", second.collationKey.sourceString) + // Punctuation is replaced with spaces, so + becomes a space + assertEquals(" ", second.collationKey.sourceString) assertEquals(Token.Type.LEXICOGRAPHIC, second.type) val third = name.tokens[2] assertEquals("2", third.collationKey.sourceString) assertEquals(Token.Type.NUMERIC, third.type) val fourth = name.tokens[3] - assertEquals(" ", fourth.collationKey.sourceString) + // Punctuation is replaced with spaces, so = becomes a space + assertEquals(" ", fourth.collationKey.sourceString) assertEquals(Token.Type.LEXICOGRAPHIC, fourth.type) val fifth = name.tokens[4] assertEquals("5", fifth.collationKey.sourceString) @@ -389,6 +394,21 @@ class NamingTest { assertEquals(-2, a.compareTo(c)) } + @Test + fun name_compareTo_intelligent_withHyphenatedNumbers() { + // This test ensures hyphenated numbers like "15-9" and "15-10" are sorted correctly. + // The hyphen should act as a token boundary, so "15-9" = [15, 9] and "15-10" = [15, 10]. + val a = Naming.intelligent().name("15-9", null) + val b = Naming.intelligent().name("15-10", null) + val c = Naming.intelligent().name("16-1", null) + // 15-9 should come before 15-10 (9 < 10 in the second token) + assertEquals(-1, a.compareTo(b)) + // 15-10 should come before 16-1 (15 < 16 in the first token) + assertEquals(-1, b.compareTo(c)) + // 15-9 should come before 16-1 (15 < 16 in the first token) + assertEquals(-1, a.compareTo(c)) + } + @Test fun name_compareTo_intelligent_withPartialSort_withoutArticle_withoutNumeric() { val a = Naming.simple().name("A", "C")