feat: meilisearcch

This commit is contained in:
Leon 2026-01-30 10:09:45 +01:00
parent 6887214402
commit 83214e654e
2 changed files with 93 additions and 2 deletions

View File

@ -79,11 +79,9 @@ class HuntsController extends Controller
$active = filter_var($request->query('active'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); $active = filter_var($request->query('active'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if ($active === true) { if ($active === true) {
// Hunt actif : start_at <= now AND (end_at IS NULL OR end_at >= now)
$filters[] = "start_at_timestamp <= {$now}"; $filters[] = "start_at_timestamp <= {$now}";
$filters[] = "(end_at_timestamp >= {$now} OR end_at_timestamp IS NULL)"; $filters[] = "(end_at_timestamp >= {$now} OR end_at_timestamp IS NULL)";
} else { } else {
// Hunt inactif : start_at > now OU end_at < now
$filters[] = "(start_at_timestamp > {$now} OR end_at_timestamp < {$now})"; $filters[] = "(start_at_timestamp > {$now} OR end_at_timestamp < {$now})";
} }
} }

View File

@ -0,0 +1,93 @@
#!/usr/bin/env php
<?php
/**
* Script de test Meilisearch - Vérification du filtre de difficulté
*
* Usage: php test-meilisearch-filters.php
*/
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
use App\Models\Hunts;
use Illuminate\Support\Facades\Log;
echo "🔍 Test des filtres Meilisearch\n\n";
// Test 1: Vérifier que les hunts existent en DB
echo "1⃣ Vérification des hunts dans la base de données:\n";
$allHunts = Hunts::all();
echo " Total hunts en DB: " . $allHunts->count() . "\n";
$huntsByDifficulty = $allHunts->groupBy('difficulty');
foreach (['easy', 'medium', 'hard'] as $diff) {
$count = isset($huntsByDifficulty[$diff]) ? $huntsByDifficulty[$diff]->count() : 0;
echo " - $diff: $count hunts\n";
}
echo "\n";
// Test 2: Vérifier ce qui est indexé dans Meilisearch
echo "2⃣ Vérification de l'indexation Meilisearch:\n";
try {
$search = Hunts::search('')->raw();
echo " Total hunts indexés: " . $search['estimatedTotalHits'] . "\n";
if (isset($search['hits'][0])) {
echo " Premier hunt indexé:\n";
$firstHunt = $search['hits'][0];
echo " - ID: " . ($firstHunt['id'] ?? 'N/A') . "\n";
echo " - Title: " . ($firstHunt['title'] ?? 'N/A') . "\n";
echo " - Difficulty: " . ($firstHunt['difficulty'] ?? 'N/A') . "\n";
echo " - City: " . ($firstHunt['city'] ?? 'N/A') . "\n";
}
} catch (Exception $e) {
echo " ❌ Erreur: " . $e->getMessage() . "\n";
}
echo "\n";
// Test 3: Test du filtre de difficulté
echo "3⃣ Test du filtre difficulty=medium:\n";
try {
$mediumHunts = Hunts::search('')
->options([
'filter' => 'difficulty = "medium"'
])
->raw();
echo " Hunts avec difficulty=medium: " . $mediumHunts['estimatedTotalHits'] . "\n";
if ($mediumHunts['estimatedTotalHits'] > 0 && isset($mediumHunts['hits'][0])) {
echo " Premier résultat:\n";
echo " - " . $mediumHunts['hits'][0]['title'] . " (difficulty: " . $mediumHunts['hits'][0]['difficulty'] . ")\n";
} else {
echo " ⚠️ Aucun hunt trouvé avec difficulty=medium\n";
echo " Vérifiez que les hunts ont bien été réindexés avec:\n";
echo " php artisan scout:import \"App\\Models\\Hunts\"\n";
}
} catch (Exception $e) {
echo " ❌ Erreur: " . $e->getMessage() . "\n";
}
echo "\n";
// Test 4: Vérifier les attributs filtrables
echo "4⃣ Vérification des settings Meilisearch:\n";
try {
$client = app(\Laravel\Scout\EngineManager::class)->engine();
$meilisearchClient = $client->engine;
$index = $meilisearchClient->index('hunts');
$settings = $index->getSettings();
echo " Attributs filtrables: " . implode(', ', $settings['filterableAttributes'] ?? []) . "\n";
echo " Attributs triables: " . implode(', ', $settings['sortableAttributes'] ?? []) . "\n";
} catch (Exception $e) {
echo " ❌ Erreur: " . $e->getMessage() . "\n";
}
echo "\n✅ Tests terminés!\n";