优化颜色筛选
This commit is contained in:
		
							
								
								
									
										56
									
								
								api/image.go
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								api/image.go
									
									
									
									
									
								
							@@ -536,24 +536,52 @@ var ImageItems = &graphql.Field{
 | 
				
			|||||||
					return nil, err
 | 
										return nil, err
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				fmt.Println(color, r, g, b, precision)
 | 
									fmt.Println(color, r, g, b, precision)
 | 
				
			||||||
				query = query.Where(goqu.Or(
 | 
									//query = query.Where(goqu.Or(
 | 
				
			||||||
 | 
									//	goqu.And(
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_r", 0)).Gt(r-precision),
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_r", 0)).Lt(r+precision),
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_g", 0)).Gt(g-precision),
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_g", 0)).Lt(g+precision),
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_b", 0)).Gt(b-precision),
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_b", 0)).Lt(b+precision),
 | 
				
			||||||
 | 
									//	),
 | 
				
			||||||
 | 
									//	goqu.And(
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_r", 1)).Gt(r-precision),
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_r", 1)).Lt(r+precision),
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_g", 1)).Gt(g-precision),
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_g", 1)).Lt(g+precision),
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_b", 1)).Gt(b-precision),
 | 
				
			||||||
 | 
									//		goqu.L(fmt.Sprintf("web_images.color_%d_b", 1)).Lt(b+precision),
 | 
				
			||||||
 | 
									//	),
 | 
				
			||||||
 | 
									//))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									query1, _, _ := goqu.Dialect("mysql").From("web_images").Select("id").Where(
 | 
				
			||||||
					goqu.And(
 | 
										goqu.And(
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_r", 0)).Gt(r-precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_r", 0)).Gt(r-precision),
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_r", 0)).Lt(r+precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_r", 0)).Lt(r+precision),
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_g", 0)).Gt(g-precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_g", 0)).Gt(g-precision),
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_g", 0)).Lt(g+precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_g", 0)).Lt(g+precision),
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_b", 0)).Gt(b-precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_b", 0)).Gt(b-precision),
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_b", 0)).Lt(b+precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_b", 0)).Lt(b+precision),
 | 
				
			||||||
					),
 | 
										),
 | 
				
			||||||
 | 
									).ToSQL()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									query2, _, _ := goqu.Dialect("mysql").From("web_images").Select("id").Where(
 | 
				
			||||||
					goqu.And(
 | 
										goqu.And(
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_r", 1)).Gt(r-precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_r", 1)).Gt(r-precision),
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_r", 1)).Lt(r+precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_r", 1)).Lt(r+precision),
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_g", 1)).Gt(g-precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_g", 1)).Gt(g-precision),
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_g", 1)).Lt(g+precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_g", 1)).Lt(g+precision),
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_b", 1)).Gt(b-precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_b", 1)).Gt(b-precision),
 | 
				
			||||||
						goqu.L(fmt.Sprintf("web_images.color_%d_b", 1)).Lt(b+precision),
 | 
											goqu.L(fmt.Sprintf("color_%d_b", 1)).Lt(b+precision),
 | 
				
			||||||
					),
 | 
										),
 | 
				
			||||||
				))
 | 
									).ToSQL()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									query = query.Join(
 | 
				
			||||||
 | 
										goqu.L(fmt.Sprintf("(%s UNION %s) AS w", query1, query2)),
 | 
				
			||||||
 | 
										goqu.On(goqu.Ex{"web_images.id": goqu.I("w.id")}),
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user