perf(api): make batch vehicle search exact

This commit is contained in:
lingniu
2026-07-16 08:58:32 +08:00
parent 251b53125d
commit b78cf1696f
4 changed files with 68 additions and 8 deletions

View File

@@ -329,13 +329,20 @@ func buildVehicleRealtimeSQL(query url.Values) SQLQuery {
args = append(args, protocol)
}
if keywords := vehicleSearchKeywords(query); len(keywords) > 0 {
matches := make([]string, 0, len(keywords))
for _, keyword := range keywords {
matches = append(matches, "(l.vin LIKE ? OR l.plate LIKE ? OR b.plate LIKE ? OR b.phone LIKE ? OR b.oem LIKE ?)")
if strings.TrimSpace(query.Get("keywords")) != "" {
placeholders := strings.TrimSuffix(strings.Repeat("?,", len(keywords)), ",")
where = append(where, "(l.vin IN ("+placeholders+") OR l.plate IN ("+placeholders+") OR b.plate IN ("+placeholders+"))")
for range 3 {
for _, keyword := range keywords {
args = append(args, keyword)
}
}
} else {
keyword := keywords[0]
like := "%" + keyword + "%"
where = append(where, "(l.vin LIKE ? OR l.plate LIKE ? OR b.plate LIKE ? OR b.phone LIKE ? OR b.oem LIKE ?)")
args = append(args, like, like, like, like, like)
}
where = append(where, "("+strings.Join(matches, " OR ")+")")
}
switch strings.TrimSpace(query.Get("online")) {
case "online":