<commit_before><?php

class SearchController extends BaseController {

	public function anyAutocomplete()
	{

		if ( ! Input::has('query'))

			App::abort(404);

		$query = Input::get('query');

		$shows = Show::where('name', 'LIKE', '%' . $query . '%')
			->get()
			->take(5);

		foreach ($shows as $show)
		{
		
			$response[] = [
				'value' => $show->name,
				'data' => [
					'category' => 'Séries',
					'route' => 'shows',
					'id' => $show->id
				]
			];
		}

		$seasons = SeasonEpisode::where('name', 'LIKE', '%' . $query . '%')
			->get()
			->take(5);

		foreach ($seasons as $season)
		{
		
			$response[] = [
				'value' => $season->name,
				'data' => [
					'category' => 'Episódios',
					'route' => 'season-episodes',
					'id' => $season->id
				]
			];
		}

		$movies = Movie::where('title', 'LIKE', '%' . $query . '%')
			->get()
			->take(5);

		foreach ($movies as $movie)
		{
		
			$response[] = [
				'value' => $movie->title,
				'data' => [
					'category' => 'Filmes',
					'route' => 'movies',
					'id' => $movie->id
				]
			];
		}

		return Response::json([
			'suggestions' => $response
		]);<commit_msg>Optimized search<commit_after><?php

class SearchController extends BaseController {

	public function anyAutocomplete()
	{

		if ( ! Input::has('query'))

			App::abort(404);

		$query = Input::get('query');

		$results = DB::select(DB::raw(
			"(SELECT title as title, id as id, 'Filmes' as category, 'movies' as route " . 
				"FROM movies WHERE title LIKE '%$query%' LIMIT 5)" .
			"UNION ALL" .
			"(SELECT name as title, id as id, 'Séries' as category, 'shows' as route " . 
				"FROM shows WHERE name LIKE '%$query%' LIMIT 5)" .
			"UNION ALL" .
			"(SELECT name as title, id as id, 'Episódios' as category, 'season-eapisodes' as route " . 
				"FROM season_episodes WHERE name LIKE '%$query%' LIMIT 5)"
		));

		foreach ($results as $result)
		{
		
			$response[] = [
				'value' => $result->title,
				'data' => [
					'category' => $result->category,
					'route' => $result->route,
					'id' => $result->id
				]
			];
		}

		return Response::json([
			'suggestions' => $response
		]);

{'fraction_non_alphanumeric': 0.21057557323350493, 'fraction_numerical': 0.005615348619560131, 'mean_word_length': 2.7118055555555554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2120319', 'n_tokens_mistral': 976, 'n_tokens_neox': 774, 'n_words': 178}