<commit_before><?php

namespace App\Http\Controllers;

use Inertia\Inertia;
use App\Models\Release;
use Illuminate\Http\Request;
use Spatie\Searchable\Search;
use Spatie\Searchable\ModelSearchAspect;

class SearchController extends Controller
{
    public function index() {
        return Inertia::render('Search/Index');
    }

    public function results(Request $request) {
        if (!$request->input('search')) {
            return redirect()->route('front.search');
        }

        $search_results = (new Search())
            ->registerModel(Release::class, function(ModelSearchAspect $modelSearchAspect) {
                $modelSearchAspect
                   ->addSearchableAttribute('name', 'codename', 'description', 'changelog')
                   ->addExactSearchableAttribute('version', 'canonical_version');
            })
            ->perform($request->input('search'));

        return Inertia::render('Search/Results', [
            'query' => $request->input('search'),
            'results' => $search_results->map(function ($result) {
                return [
                    'title' => $result->title,
                    'url' => $result->url,
                    'type' => $result->type,
                    'searchable' => [
                        'name' => $result->searchable->name,
                        'version' => $result->searchable->version,<commit_msg>Fix search function<commit_after><?php

namespace App\Http\Controllers;

use Inertia\Inertia;
use App\Models\Release;
use Illuminate\Http\Request;
use Spatie\Searchable\Search;
use Spatie\Searchable\ModelSearchAspect;

class SearchController extends Controller
{
    public function index() {
        return Inertia::render('Search/Index');
    }

    public function results(Request $request) {
        if (!$request->input('search')) {
            return redirect()->route('front.search');
        }

        $search_results = (new Search())
            ->registerModel(Release::class, function(ModelSearchAspect $modelSearchAspect) {
                $modelSearchAspect
                   ->addSearchableAttribute('name')
                   ->addSearchableAttribute('codename')
                   ->addSearchableAttribute('description')
                   ->addSearchableAttribute('changelog')
                   ->addExactSearchableAttribute('version')
                   ->addExactSearchableAttribute('canonical_version');
            })
            ->perform($request->input('search'));

        return Inertia::render('Search/Results', [
            'query' => $request->input('search'),
            'results' => $search_results->map(function ($result) {
                return [
                    'title' => $result->title,
                    'url' => $result->url,
                    'type' => $result->type,
                    'searchable' => [
                        'name' => $result->searchable->name,
                        'version' => $result->searchable->version,
{'fraction_non_alphanumeric': 0.1373534338358459, 'fraction_numerical': 0.0, 'mean_word_length': 2.094300518134715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1998595', 'n_tokens_mistral': 763, 'n_tokens_neox': 744, 'n_words': 127}