@php $locale = app()->getLocale(); $tabLabels = ['all' => __('site.search_tab_all')]; if (site_shows_products()) { $tabLabels['products'] = __('site.search_tab_products'); $tabLabels['categories'] = __('site.search_tab_categories'); } if (site_feature_enabled('articles_blog')) { $tabLabels['articles'] = __('site.search_tab_articles'); } if (site_feature_enabled('news')) { $tabLabels['news'] = __('site.search_tab_news'); } if (site_shows_services()) { $tabLabels['services'] = __('site.search_tab_services'); } $trendingLimit = (int) config('site.search.trending_limit', 8); $articleCounts = \App\Models\Article::query() ->active() ->whereNotNull('category_id') ->selectRaw('category_id, COUNT(*) as aggregate') ->groupBy('category_id') ->pluck('aggregate', 'category_id'); $trendingCategories = \App\Models\Category::query() ->active() ->where(fn ($query) => $query->where('parent_id', 0)->orWhereNull('parent_id')) ->orderBy('name_fa') ->get(); if ($trendingCategories->isEmpty()) { $trendingCategories = \App\Models\Category::query() ->active() ->orderBy('name_fa') ->limit($trendingLimit) ->get(); } $trending = $trendingCategories ->sortByDesc(fn ($category) => (int) $articleCounts->get($category->id, 0)) ->take($trendingLimit) ->map(fn ($category) => locale_category_name($category)) ->filter(fn ($name) => is_string($name) && trim($name) !== '') ->unique() ->values() ->all(); $config = [ 'searchRoute' => route('site.search', ['locale' => $locale]), 'suggestionsRoute' => route('site.search.suggestions', ['locale' => $locale]), 'minQueryLength' => (int) config('site.search.min_query_length', 2), 'historyLimit' => (int) config('site.search.history_limit', 6), 'debounceMs' => (int) config('site.search.debounce_ms', 220), 'trending' => $trending, 'loadError' => __('site.search_error_loading'), 'tabLabels' => $tabLabels, ]; @endphp