fix(syb): accept descriptive color specs (#274)

This commit is contained in:
QiuSW
2026-09-14 10:52:02 +08:00
parent e0ed05d15a
commit b83f20c6b7
+1 -5
View File
@@ -25,7 +25,6 @@ var explicitSizePattern = regexp.MustCompile(`(?i)^(?:均(?:码|碼|号|號)|one
// Observed in the real SYB sample: "黑色+白色【純棉兩件裝】 簡約親膚" strips
// its bracket to "黑色+白色 簡約親膚", which still carries a '+' and internal
// whitespace, so it must not be reported as a confident match.
var ambiguousPattern = regexp.MustCompile(`[++\s]`)
// ParseResult is the color/size candidate extracted from one productSpec
// string, plus how much the caller should trust it.
@@ -91,7 +90,7 @@ func Parse(raw string) ParseResult {
if explicitSizePattern.MatchString(only) {
return ParseResult{Size: only, Status: models.SYBParseStatusSuccess, Note: "仅识别到尺码"}
}
if only != "" && !ambiguousPattern.MatchString(only) {
if only != "" {
return ParseResult{Color: only, Status: models.SYBParseStatusSuccess, Note: "仅识别到颜色"}
}
return ParseResult{Color: colorPart, Size: sizePart, Status: models.SYBParseStatusFailed, Note: "按逗号拆分后没有可靠规格"}
@@ -103,9 +102,6 @@ func Parse(raw string) ParseResult {
if firstIsSize {
colorPart, sizePart = secondPart, firstPart
}
if ambiguousPattern.MatchString(colorPart) {
return ParseResult{Color: colorPart, Size: sizePart, Status: models.SYBParseStatusUncertain, Note: "颜色部分含备注文本或多个分隔符,拆分结果可能不准确"}
}
return ParseResult{Color: colorPart, Size: sizePart, Status: models.SYBParseStatusSuccess}
}