diff --git a/svc/routes/product_images.go b/svc/routes/product_images.go index cd35e80..1538a69 100644 --- a/svc/routes/product_images.go +++ b/svc/routes/product_images.go @@ -77,6 +77,22 @@ func firstThreeDigitToken(tokens []string) string { return "" } +func filePrimaryMatchesDim1(fileName, dim1 string) bool { + dim1 = strings.ToUpper(strings.TrimSpace(dim1)) + if dim1 == "" { + return true + } + tokens := tokenizeImageFileName(fileName) + if len(tokens) == 0 { + return true + } + primary := firstThreeDigitToken(tokens) + if primary == "" { + return true + } + return primary == dim1 +} + func imageFileMatches(fileName, dim1, dim3 string) bool { dim1 = strings.ToUpper(strings.TrimSpace(dim1)) dim3 = strings.ToUpper(strings.TrimSpace(dim3)) @@ -322,7 +338,7 @@ ORDER BY if len(targetDimval1) > 0 { clustered := make([]ProductImageItem, 0, len(items)) for _, it := range items { - if _, ok := targetDimval1[rowDim1ByID[it.ID]]; ok { + if _, ok := targetDimval1[rowDim1ByID[it.ID]]; ok && filePrimaryMatchesDim1(it.FileName, dim1Upper) { clustered = append(clustered, it) } }