private function searchPosts(string $question): array
{
$tokens = $this->tokenize($question); // 불용어 제거 + 조사 변형 포함
$posts = (new PostModel())->where('spam_status', 'approved')->findAll();
foreach ($posts as $post) {
$score = 0.0;
foreach ($tokens as $tok => $weight) {
$titleHits = substr_count(mb_strtolower($post->title), $tok);
$textHits = substr_count(mb_strtolower($post->content), $tok);
$score += ($titleHits * 5 + $textHits) * $weight;
}
if ($score > 0) $results[] = ['post' => $post, 'score' => $score];
}
usort($results, fn($a, $b) => $b['score'] <=> $a['score']);
return array_slice($results, 0, 5);
}