perf(api): make batch vehicle search exact
This commit is contained in:
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user