moteur de recherche : trigram+substring, navbar, page resultats

This commit is contained in:
Cedric Abonnel
2026-05-12 01:29:01 +02:00
parent 3a5ae2631d
commit f236ea24de
9 changed files with 465 additions and 74 deletions
+82
View File
@@ -1068,3 +1068,85 @@ footer {
.star-rating label:hover ~ label {
color: #f5a623;
}
/* ─── Barre de recherche (navbar) ────────── */
.search-form {
margin: 0 .5rem;
}
.search-input {
width: 160px;
transition: width .2s;
background: var(--vl-surface);
border-color: var(--vl-border);
color: var(--vl-text);
}
.search-input:focus {
width: 220px;
box-shadow: 0 0 0 2px rgba(var(--vl-accent-rgb, 59,130,246), .25);
}
@media (max-width: 991px) {
.search-form { margin: .5rem 0; }
.search-input, .search-input:focus { width: 100%; }
}
/* ─── Page de recherche ───────────────────── */
.search-page { max-width: 780px; margin: 0 auto; }
.search-bar .input-group { max-width: 600px; }
.search-results { display: flex; flex-direction: column; gap: 2rem; }
.search-result {
border-bottom: 1px solid var(--vl-border);
padding-bottom: 1.5rem;
}
.search-result-meta {
display: flex;
align-items: center;
gap: .75rem;
margin-bottom: .25rem;
font-size: .8rem;
}
.search-result-cat {
background: var(--vl-surface);
border: 1px solid var(--vl-border);
border-radius: 20px;
padding: 1px 10px;
color: var(--vl-muted);
text-decoration: none;
}
.search-result-cat:hover { color: var(--vl-accent); }
.search-result-date { color: var(--vl-muted); }
.search-result-title {
font-size: 1.15rem;
margin: 0 0 .4rem;
}
.search-result-title a {
color: var(--vl-text);
text-decoration: none;
}
.search-result-title a:hover { color: var(--vl-accent); }
.search-result-snippet {
font-size: .9rem;
color: var(--vl-muted);
margin: 0;
line-height: 1.6;
}
.search-result-snippet mark {
background: rgba(250, 204, 21, .35);
color: inherit;
border-radius: 2px;
padding: 0 2px;
}
+21
View File
@@ -1502,6 +1502,27 @@ switch ($action) {
include BASE_PATH . '/templates/profile.php';
break;
case 'search':
require_once BASE_PATH . '/src/SearchEngine.php';
$searchQuery = trim($_GET['q'] ?? '');
$searchResults = [];
if ($searchQuery !== '') {
$privateCats = $articles->getPrivateCategories();
$searchPool = array_values(array_filter($articles->getAll(true), static function (array $a) use ($privateCats): bool {
$cat = trim($a['category'] ?? '');
if ($cat !== '' && in_array($cat, $privateCats, true) && !isLoggedIn()) {
return false;
}
if (strtotime((string)($a['published_at'] ?? '')) > time() && !isLoggedIn()) {
return false;
}
return true;
}));
$searchResults = (new SearchEngine())->search($searchQuery, $searchPool);
}
include BASE_PATH . '/templates/search.php';
break;
case 'list':
default:
$privateCats = $articles->getPrivateCategories();