Browse Source

:art: Improve database block/text/asset/template/relation/rollup field sorting https://github.com/siyuan-note/siyuan/issues/12454

Daniel 10 months ago
parent
commit
3a9fb0d9e3
1 changed files with 24 additions and 6 deletions
  1. 24 6
      kernel/av/sort.go

+ 24 - 6
kernel/av/sort.go

@@ -44,7 +44,10 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
 	switch value.Type {
 	switch value.Type {
 	case KeyTypeBlock:
 	case KeyTypeBlock:
 		if nil != value.Block && nil != other.Block {
 		if nil != value.Block && nil != other.Block {
-			return strings.Compare(value.Block.Content, other.Block.Content)
+			if util.PinYinCompare(value.Block.Content, other.Block.Content) {
+				return -1
+			}
+			return 1
 		}
 		}
 	case KeyTypeText:
 	case KeyTypeText:
 		if nil != value.Text && nil != other.Text {
 		if nil != value.Text && nil != other.Text {
@@ -56,7 +59,10 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
 			} else if "" == other.Text.Content {
 			} else if "" == other.Text.Content {
 				return -1
 				return -1
 			}
 			}
-			return strings.Compare(value.Text.Content, other.Text.Content)
+			if util.PinYinCompare(value.Text.Content, other.Text.Content) {
+				return -1
+			}
+			return 1
 		}
 		}
 	case KeyTypeNumber:
 	case KeyTypeNumber:
 		if nil != value.Number && nil != other.Number {
 		if nil != value.Number && nil != other.Number {
@@ -223,7 +229,10 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
 			for _, v := range other.MAsset {
 			for _, v := range other.MAsset {
 				v2 += v.Content
 				v2 += v.Content
 			}
 			}
-			return strings.Compare(v1, v2)
+			if util.PinYinCompare(v1, v2) {
+				return -1
+			}
+			return 1
 		}
 		}
 	case KeyTypeTemplate:
 	case KeyTypeTemplate:
 		if nil != value.Template && nil != other.Template {
 		if nil != value.Template && nil != other.Template {
@@ -238,7 +247,10 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
 				}
 				}
 				return 0
 				return 0
 			}
 			}
-			return strings.Compare(value.Template.Content, other.Template.Content)
+			if util.PinYinCompare(value.Template.Content, other.Template.Content) {
+				return -1
+			}
+			return 1
 		}
 		}
 	case KeyTypeCheckbox:
 	case KeyTypeCheckbox:
 		if nil != value.Checkbox && nil != other.Checkbox {
 		if nil != value.Checkbox && nil != other.Checkbox {
@@ -278,7 +290,10 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
 				oContentBuf.WriteByte(' ')
 				oContentBuf.WriteByte(' ')
 			}
 			}
 			oContent := strings.TrimSpace(oContentBuf.String())
 			oContent := strings.TrimSpace(oContentBuf.String())
-			return strings.Compare(vContent, oContent)
+			if util.PinYinCompare(vContent, oContent) {
+				return -1
+			}
+			return 1
 		}
 		}
 	case KeyTypeRollup:
 	case KeyTypeRollup:
 		if nil != value.Rollup && nil != other.Rollup {
 		if nil != value.Rollup && nil != other.Rollup {
@@ -308,7 +323,10 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
 				oContentBuf.WriteByte(' ')
 				oContentBuf.WriteByte(' ')
 			}
 			}
 			oContent := strings.TrimSpace(oContentBuf.String())
 			oContent := strings.TrimSpace(oContentBuf.String())
-			return strings.Compare(vContent, oContent)
+			if util.PinYinCompare(vContent, oContent) {
+				return -1
+			}
+			return 1
 		}
 		}
 	}
 	}
 	return 0
 	return 0