Skip to content

Commit 650493d

Browse files
committed
🎨 Improve database field sorting for content containing emojis #14323
1 parent 020dfab commit 650493d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

kernel/av/sort.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
6868
return 0
6969
}
7070

71-
if util.PinYinCompare(value.Text.Content, other.Text.Content) {
71+
if util.EmojiPinYinCompare(value.Text.Content, other.Text.Content) {
7272
return -1
7373
}
7474
return 1
@@ -243,7 +243,7 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
243243
return 0
244244
}
245245

246-
if util.PinYinCompare(v1, v2) {
246+
if util.EmojiPinYinCompare(v1, v2) {
247247
return -1
248248
}
249249
return 1
@@ -266,7 +266,7 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
266266
return 0
267267
}
268268

269-
if util.PinYinCompare(value.Template.Content, other.Template.Content) {
269+
if util.EmojiPinYinCompare(value.Template.Content, other.Template.Content) {
270270
return -1
271271
}
272272
return 1
@@ -314,7 +314,7 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
314314
return 0
315315
}
316316

317-
if util.PinYinCompare(vContent, oContent) {
317+
if util.EmojiPinYinCompare(vContent, oContent) {
318318
return -1
319319
}
320320
return 1
@@ -352,7 +352,7 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
352352
return 0
353353
}
354354

355-
if util.PinYinCompare(vContent, oContent) {
355+
if util.EmojiPinYinCompare(vContent, oContent) {
356356
return -1
357357
}
358358
return 1

kernel/util/sort.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ func NaturalCompare(str1, str2 string) bool {
3232
return natsort.Compare(str1, str2)
3333
}
3434

35+
func EmojiPinYinCompare(str1, str2 string) bool {
36+
str1_ := strings.TrimSpace(RemoveEmojiInvisible(str1))
37+
str2_ := strings.TrimSpace(RemoveEmojiInvisible(str2))
38+
if str1_ == str2_ && 0 == len(str1_) {
39+
// 全部都是 emoji 的情况按 emoji 字符串排序
40+
return strings.Compare(str1, str2) < 0
41+
}
42+
return PinYinCompare(str1, str2)
43+
}
44+
3545
func PinYinCompare(str1, str2 string) bool {
3646
str1 = RemoveEmojiInvisible(str1)
3747
str2 = RemoveEmojiInvisible(str2)

0 commit comments

Comments
 (0)