检索精度 precision
This commit is contained in:
@@ -778,19 +778,32 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
|||||||
// 逗号分割且去除空格
|
// 逗号分割且去除空格
|
||||||
colors := strings.Split(strings.ReplaceAll(p.Args["color"].(string), " ", ""), ",")
|
colors := strings.Split(strings.ReplaceAll(p.Args["color"].(string), " ", ""), ",")
|
||||||
for index, color := range colors {
|
for index, color := range colors {
|
||||||
|
|
||||||
|
var precision int = 10
|
||||||
|
if strings.Contains(color, ":") {
|
||||||
|
re := regexp.MustCompile(`^#([0-9a-fA-F]{6}):(\d+)$`)
|
||||||
|
matches := re.FindStringSubmatch(color)
|
||||||
|
num, err := strconv.Atoi(matches[2])
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("数字精度转换失败:", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
precision = num
|
||||||
|
}
|
||||||
|
|
||||||
r, g, b, err := hexToRGB(color)
|
r, g, b, err := hexToRGB(color)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("hexToRGB", index, err)
|
fmt.Println("hexToRGB", index, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fmt.Println(color, r, g, b)
|
fmt.Println(color, r, g, b, precision)
|
||||||
query = query.Where(goqu.And(
|
query = query.Where(goqu.And(
|
||||||
goqu.L(fmt.Sprintf("web_images.color_%d_r", index)).Gt(r-10),
|
goqu.L(fmt.Sprintf("web_images.color_%d_r", index)).Gt(r-precision),
|
||||||
goqu.L(fmt.Sprintf("web_images.color_%d_r", index)).Lt(r+10),
|
goqu.L(fmt.Sprintf("web_images.color_%d_r", index)).Lt(r+precision),
|
||||||
goqu.L(fmt.Sprintf("web_images.color_%d_g", index)).Gt(g-10),
|
goqu.L(fmt.Sprintf("web_images.color_%d_g", index)).Gt(g-precision),
|
||||||
goqu.L(fmt.Sprintf("web_images.color_%d_g", index)).Lt(g+10),
|
goqu.L(fmt.Sprintf("web_images.color_%d_g", index)).Lt(g+precision),
|
||||||
goqu.L(fmt.Sprintf("web_images.color_%d_b", index)).Gt(b-10),
|
goqu.L(fmt.Sprintf("web_images.color_%d_b", index)).Gt(b-precision),
|
||||||
goqu.L(fmt.Sprintf("web_images.color_%d_b", index)).Lt(b+10),
|
goqu.L(fmt.Sprintf("web_images.color_%d_b", index)).Lt(b+precision),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user