@extends('ui-theme.' . env('THEME_FOLDER') . '.layout.ui-main') @section('content') @php $breadcrumbType = 'without_image'; $page = null; $headerImage = asset('assets/images/breadcrumb-bg.jpg'); @endphp @php // Lightweight highlight + excerpt helper for search results if (!function_exists('search_snippet_highlight')) { function search_snippet_highlight($text, $query, $limit = 160) { $text = trim(strip_tags((string)($text ?? ''))); if ($text === '') return ''; // Skip obvious URLs/paths and file-like strings if (preg_match('/^https?:\/\//i', $text)) return ''; if (preg_match('~^data:[a-z]+\/[a-z0-9+.-]+;base64,~i', $text)) return ''; if (preg_match('~(^|/)((storage|uploads|files)(/|$))~iu', $text)) return ''; if (preg_match('~\.(?:jpe?g|png|gif|svg|webp|pdf|docx?|xlsx?|pptx?|mp4|mov|avi|zip|rar)(?:\?.*)?$~iu', $text)) return ''; $q = trim((string)($query ?? '')); if ($q === '') { return \Illuminate\Support\Str::limit($text, $limit); } // Tokenize query to highlight each word $tokens = array_values(array_filter(preg_split('/\s+/u', $q))); $anchor = $tokens[0] ?? $q; // Find best anchor position for centered excerpt $pos = mb_stripos($text, $anchor); if ($pos === false) { foreach ($tokens as $t) { $pos = mb_stripos($text, $t); if ($pos !== false) break; } } if ($pos === false) { // No match in this field; do not render a snippet return ''; } else { $start = max(0, $pos - (int)($limit / 2)); $snippet = mb_substr($text, $start, $limit); if ($start > 0) $snippet = '…' . ltrim($snippet); if ($start + $limit < mb_strlen($text)) $snippet = rtrim($snippet) . '…'; } // Build a case-insensitive pattern to wrap matches $escaped = array_map(fn($t) => preg_quote($t, '/'), $tokens); if (empty($escaped)) $escaped = [preg_quote($q, '/')]; $pattern = '/(' . implode('|', $escaped) . ')/iu'; $highlighted = preg_replace($pattern, '$1', $snippet); return $highlighted; } } @endphp
{{ $translations['search.result.title'] ?? '' }}
@if(!$query)
{{ $translations['search.empty_search'] ?? '' }}
@else @php $total = ($pages?->count() ?? 0) + ($products?->count() ?? 0) + ($productCategories?->count() ?? 0) + ($blogs?->count() ?? 0); @endphp

{{ $translations['searchresults_found'] ?? '' }} {{ $query }} {{ $translations['search.result.for'] ?? '' }} {{ $total }} {{ $translations['search.result.forend'] ?? '' }}

@if(($pages?->count() ?? 0) > 0)
    @foreach($pages as $item)
  • @php $url = $item->menu?->slug ? url('/'.$item->slug) : url('/'.$item->slug); @endphp {{ $item->title }} @php $pageSnippet = search_snippet_highlight($item->description ?? '', $query, 160) ?: search_snippet_highlight($item->content ?? '', $query, 160) ?: search_snippet_highlight($item->meta_description ?? '', $query, 160) ?: search_snippet_highlight($item->search_component_text ?? '', $query, 160); @endphp @if($pageSnippet)
    {!! $pageSnippet !!}
    @endif
  • @endforeach
@endif @if(($products?->count() ?? 0) > 0)
    @foreach($products as $product)
  • {{ $product->name }} @php $productSnippet = search_snippet_highlight($product->description ?? '', $query, 160) ?: search_snippet_highlight($product->additional_info_json ?? '', $query, 160) ?: search_snippet_highlight($product->meta_description ?? '', $query, 160); @endphp @if($productSnippet)
    {!! $productSnippet !!}
    @endif
  • @endforeach
@endif @if(($productCategories?->count() ?? 0) > 0)
    @foreach($productCategories as $category)
  • {{ $category->name }} @php $catSnippet = search_snippet_highlight($category->description ?? '', $query, 160) ?: search_snippet_highlight($category->meta_description ?? '', $query, 160); @endphp @if($catSnippet)
    {!! $catSnippet !!}
    @endif
  • @endforeach
@endif @if(($blogs?->count() ?? 0) > 0)
    @foreach($blogs as $blog)
  • {{ $blog->title }} @php $blogSnippet = search_snippet_highlight($blog->excerpt ?? '', $query, 160) ?: search_snippet_highlight($blog->content ?? '', $query, 160) ?: search_snippet_highlight($blog->meta_description ?? '', $query, 160); @endphp @if($blogSnippet)
    {!! $blogSnippet !!}
    @endif
  • @endforeach
@endif @if($total === 0)
{{ $translations['search.no_results'] ?? '' }}
@endif @endif
@endsection