asdasd
This commit is contained in:
@@ -26,13 +26,13 @@ final class Search
|
|||||||
foreach ($tokens as $tok) {
|
foreach ($tokens as $tok) {
|
||||||
$tok = trim($tok);
|
$tok = trim($tok);
|
||||||
if ($tok === '') continue;
|
if ($tok === '') continue;
|
||||||
$conditions[] = "(title LIKE :t{$i}a OR teaser_public LIKE :t{$i}b OR description LIKE :t{$i}c OR city LIKE :t{$i}d OR region LIKE :t{$i}e OR zip LIKE :t{$i}f)";
|
$conditions[] = "(title LIKE ? OR teaser_public LIKE ? OR description LIKE ? OR city LIKE ? OR region LIKE ? OR zip LIKE ?)";
|
||||||
$bind["t{$i}a"] = '%' . $tok . '%';
|
$bind[] = '%' . $tok . '%';
|
||||||
$bind["t{$i}b"] = '%' . $tok . '%';
|
$bind[] = '%' . $tok . '%';
|
||||||
$bind["t{$i}c"] = '%' . $tok . '%';
|
$bind[] = '%' . $tok . '%';
|
||||||
$bind["t{$i}d"] = '%' . $tok . '%';
|
$bind[] = '%' . $tok . '%';
|
||||||
$bind["t{$i}e"] = '%' . $tok . '%';
|
$bind[] = '%' . $tok . '%';
|
||||||
$bind["t{$i}f"] = '%' . $tok . '%';
|
$bind[] = '%' . $tok . '%';
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,67 +53,38 @@ final class Search
|
|||||||
$radius = isset($geo['radius']) && is_numeric($geo['radius']) ? max(0.1, (float)$geo['radius']) : 5.0;
|
$radius = isset($geo['radius']) && is_numeric($geo['radius']) ? max(0.1, (float)$geo['radius']) : 5.0;
|
||||||
$sql .= ",
|
$sql .= ",
|
||||||
(6371 * ACOS(LEAST(1,
|
(6371 * ACOS(LEAST(1,
|
||||||
COS(RADIANS(:glat)) * COS(RADIANS(lat)) * COS(RADIANS(lng) - RADIANS(:glng)) +
|
COS(RADIANS(?)) * COS(RADIANS(lat)) * COS(RADIANS(lng) - RADIANS(?)) +
|
||||||
SIN(RADIANS(:glat)) * SIN(RADIANS(lat))
|
SIN(RADIANS(?)) * SIN(RADIANS(lat))
|
||||||
))) AS distance_km";
|
))) AS distance_km";
|
||||||
$distanceFiltering = true;
|
$distanceFiltering = true;
|
||||||
|
|
||||||
$latRange = $radius / 111.0;
|
$latRange = $radius / 111.0;
|
||||||
$lngRange = $radius / (111.0 * max(0.1, cos($lat * M_PI / 180)));
|
$lngRange = $radius / (111.0 * max(0.1, cos($lat * M_PI / 180)));
|
||||||
$whereParts[] = "(lat IS NOT NULL AND lng IS NOT NULL)";
|
$whereParts[] = "(lat IS NOT NULL AND lng IS NOT NULL)";
|
||||||
$whereParts[] = "(lat BETWEEN :latMin AND :latMax)";
|
$whereParts[] = "(lat BETWEEN ? AND ?)";
|
||||||
$whereParts[] = "(lng BETWEEN :lngMin AND :lngMax)";
|
$whereParts[] = "(lng BETWEEN ? AND ?)";
|
||||||
$bind['glat'] = $lat;
|
$bind[] = $lat;
|
||||||
$bind['glng'] = $lng;
|
$bind[] = $lng;
|
||||||
$bind['latMin'] = $lat - $latRange;
|
$bind[] = $lat;
|
||||||
$bind['latMax'] = $lat + $latRange;
|
$bind[] = $lat - $latRange;
|
||||||
$bind['lngMin'] = $lng - $lngRange;
|
$bind[] = $lat + $latRange;
|
||||||
$bind['lngMax'] = $lng + $lngRange;
|
$bind[] = $lng - $lngRange;
|
||||||
$bind['radius'] = $radius;
|
$bind[] = $lng + $lngRange;
|
||||||
|
$bind[] = $radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
$where = $whereParts ? ('WHERE ' . implode(' AND ', $whereParts)) : '';
|
$where = $whereParts ? ('WHERE ' . implode(' AND ', $whereParts)) : '';
|
||||||
$sql .= " FROM events $where";
|
$sql .= " FROM events $where";
|
||||||
if ($distanceFiltering) {
|
if ($distanceFiltering) {
|
||||||
$sql .= " HAVING distance_km <= :radius";
|
$sql .= " HAVING distance_km <= ?";
|
||||||
$sql .= " ORDER BY distance_km ASC, starts_at ASC";
|
$sql .= " ORDER BY distance_km ASC, starts_at ASC";
|
||||||
} else {
|
} else {
|
||||||
$sql .= " ORDER BY starts_at ASC";
|
$sql .= " ORDER BY starts_at ASC";
|
||||||
}
|
}
|
||||||
$sql .= " LIMIT :lim";
|
$limit = (int)$limit;
|
||||||
$bind['lim'] = (int)$limit;
|
$sql .= " LIMIT {$limit}";
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare($sql);
|
$stmt = $this->pdo->prepare($sql);
|
||||||
// Fix gebunden, um Parameter-Mismatch auszuschließen
|
|
||||||
$stmt->bindValue(':t0a', $bind['t0a'] ?? '', \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':t0b', $bind['t0b'] ?? '', \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':t0c', $bind['t0c'] ?? '', \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':t0d', $bind['t0d'] ?? '', \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':t0e', $bind['t0e'] ?? '', \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':t0f', $bind['t0f'] ?? '', \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':glat', $bind['glat'] ?? null, \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':glng', $bind['glng'] ?? null, \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':latMin', $bind['latMin'] ?? null, \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':latMax', $bind['latMax'] ?? null, \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':lngMin', $bind['lngMin'] ?? null, \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':lngMax', $bind['lngMax'] ?? null, \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':radius', $bind['radius'] ?? null, \PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue(':lim', $bind['lim'] ?? (int)$limit, \PDO::PARAM_INT);
|
|
||||||
|
|
||||||
if (defined('APP_ENV') && APP_ENV === 'staging') {
|
|
||||||
$ph = [];
|
|
||||||
if (preg_match_all('/:([a-zA-Z0-9_]+)/', $sql, $m)) {
|
|
||||||
$ph = array_unique($m[0]);
|
|
||||||
}
|
|
||||||
$paramKeys = array_keys($bind);
|
|
||||||
$log = [
|
|
||||||
'placeholders' => $ph,
|
|
||||||
'params' => $paramKeys,
|
|
||||||
'sql' => $sql,
|
|
||||||
'bind' => $bind,
|
|
||||||
];
|
|
||||||
@file_put_contents(__DIR__ . '/../../debug/search_debug.log', print_r($log, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|||||||
Reference in New Issue
Block a user