From 83214e654e5e6c8251635bf4f8cdd62f5b0a0577 Mon Sep 17 00:00:00 2001 From: Leon Date: Fri, 30 Jan 2026 10:09:45 +0100 Subject: [PATCH] feat: meilisearcch --- app/Http/Controllers/HuntsController.php | 2 - test-meilisearch-filters.php | 93 ++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 test-meilisearch-filters.php diff --git a/app/Http/Controllers/HuntsController.php b/app/Http/Controllers/HuntsController.php index 12fb593..187564e 100644 --- a/app/Http/Controllers/HuntsController.php +++ b/app/Http/Controllers/HuntsController.php @@ -79,11 +79,9 @@ class HuntsController extends Controller $active = filter_var($request->query('active'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); if ($active === true) { - // Hunt actif : start_at <= now AND (end_at IS NULL OR end_at >= now) $filters[] = "start_at_timestamp <= {$now}"; $filters[] = "(end_at_timestamp >= {$now} OR end_at_timestamp IS NULL)"; } else { - // Hunt inactif : start_at > now OU end_at < now $filters[] = "(start_at_timestamp > {$now} OR end_at_timestamp < {$now})"; } } diff --git a/test-meilisearch-filters.php b/test-meilisearch-filters.php new file mode 100644 index 0000000..205a353 --- /dev/null +++ b/test-meilisearch-filters.php @@ -0,0 +1,93 @@ +#!/usr/bin/env php +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";