input('search'); $category = $request->input('category'); $page = $request->input('page', 1); try { $index = app(BuildStaticFileIndexTask::class)->run(); $results = []; $normalizedQuery = $this->normalizeText(Str::lower($query)); foreach ($index as $filePath => $content) { if (stripos($content['content'], $normalizedQuery) !== false) { $relativePath = str_replace(public_path() . '/', '', $filePath); $results[] = [ 'file' => $relativePath, 'content' => $content['title'], 'category' => trim($content['category']), ]; } } $categories = array_values(array_unique(array_filter(array_column($results, 'category')))); if ($category !== null) { $results = array_filter($results, function($item) use ($category) { return $item['category'] === $category; }); // Переиндексировать массив $results = array_values($results); } return app(PaginateSearchResultsTask::class)->run($results, $page, self::PER_PAGE, $categories); } catch (\Exception $e) { Log::channel('app')->error('Search error: ' . $e->getMessage()); return [ 'data' => [], 'meta' => [ 'current_page' => 1, 'total' => 0, 'per_page' => self::PER_PAGE, 'last_page' => 1 ] ]; } } protected function normalizeText(string $text): string { $text = html_entity_decode($text, ENT_QUOTES | ENT_HTML5, 'UTF-8'); $text = preg_replace('/\s+/u', ' ', $text); $text = trim($text); return Str::lower($text); } protected function getFirstH1Content(string $content): ?string { try { if (preg_match('/