PHP code example of tag1 / scolta-laravel

1. Go to this page and download the library: Download tag1/scolta-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tag1 / scolta-laravel example snippets


// app/Models/Recipe.php
use Tag1\Scolta\Export\ContentItem;
use Tag1\ScoltaLaravel\Searchable;

class Recipe extends Model
{
    use Searchable;

    public function toSearchableContent(): ContentItem
    {
        return new ContentItem(
            id:       "recipe-{$this->id}",
            title:    $this->name,
            bodyHtml: "<p>{$this->description}</p>"
                    . "<h2>Ingredients</h2><ul>"
                    . implode('', array_map(fn($i) => "<li>{$i}</li>", $this->ingredients))
                    . "</ul><p>Tags: {$this->tags}, {$this->regional_synonyms}</p>",
            url:      "/recipes/{$this->slug}",
            date:     $this->updated_at->format('Y-m-d'),
            siteName: config('scolta.site_name', config('app.name')),
        );
    }

    public function scopeSearchable($query)
    {
        return $query->where('published', true);
    }
}

'models' => [App\Models\Recipe::class],

// config/scolta.php
'ai_languages' => ['en', 'fr', 'de'],

// config/scolta.php
'scoring' => [
    'recency_boost_max'           => 0.8,
    'recency_half_life_days'      => 30,
    'recency_penalty_after_days'  => 365,
    'recency_max_penalty'         => 0.5,
],

'scoring' => [
    'recency_strategy'           => 'none',
    'title_match_boost'          => 2.0,
    'title_all_terms_multiplier' => 2.5,
],

'scoring' => [
    'recency_strategy'           => 'none',
    'title_match_boost'          => 1.5,
    'title_all_terms_multiplier' => 2.0,
],

// app/Listeners/EnrichScoltaPrompt.php
use Tag1\ScoltaLaravel\Events\PromptEnrichEvent;

class EnrichScoltaPrompt
{
    public function handle(PromptEnrichEvent $event): void
    {
        if ($event->promptName === 'summarize') {
            $event->resolvedPrompt .= "\n\nFocus on dietary information and cuisine type.";
        }
    }
}

protected $listen = [
    \Tag1\ScoltaLaravel\Events\PromptEnrichEvent::class => [
        \App\Listeners\EnrichScoltaPrompt::class,
    ],
];

// config/scolta.php
'amazee_middleware' => ['web', 'auth'],

// config/scolta.php
'ai_summary_top_n'     => 15,
'ai_summary_max_chars' => 6000,

'ai_languages' => ['de'],  // or ['en', 'fr', 'de'] for multilingual

// config/scolta.php
'scoring' => [
    'expand_primary_weight' => 0.8,  // closer to 1.0 = original query dominates
],
// or: 'ai_expand_query' => false,

use Tag1\Scolta\Export\ContentItem;
use Tag1\ScoltaLaravel\Searchable;

class Article extends Model
{
    use Searchable;

    public function toSearchableContent(): ContentItem
    {
        return new ContentItem(
            id:       "article-{$this->id}",
            title:    $this->title,
            bodyHtml: $this->body,
            url:      "/articles/{$this->slug}",
            date:     $this->updated_at->format('Y-m-d'),
            siteName: config('scolta.site_name', config('app.name')),
        );
    }

    // Optional: filter which records to index
    public function scopeSearchable($query)
    {
        return $query->where('published', true);
    }
}

'models' => [
    App\Models\Article::class,
    App\Models\Page::class,
],

Gate::define('scolta.health-detail', fn (User $user) => $user->isAdmin());

use Illuminate\Support\Facades\Schedule;

Schedule::command('scolta:build --incremental')->everyFifteenMinutes();

protected function schedule(Schedule $schedule): void
{
    $schedule->command('scolta:build --incremental')->everyFifteenMinutes();
}
bash
php artisan scolta:build
bash
php artisan scolta:check-setup
bash
php artisan scolta:status
bash
php artisan scolta:build --memory-budget=balanced
json
"scripts": {
    "post-autoload-dump": [
        "@php artisan package:discover --ansi",
        "@php artisan vendor:publish --tag=scolta-assets --force --ansi"
    ]
}
bash
php artisan vendor:publish --tag=scolta-assets --force
bash
php artisan scolta:amazee:provision [email protected]
bash
php artisan vendor:publish --tag=scolta-migrations
php artisan migrate
bash
php artisan scolta:check-setup
php artisan scolta:status
bash
php artisan queue:work --tries=3

* * * * * cd /var/www/html && php artisan schedule:run 2>&1 | logger -t scolta

*/15 * * * * cd /var/www/html && php artisan scolta:build --incremental 2>&1 | logger -t scolta
bash
cd test-laravel-12
ddev exec php vendor/bin/phpunit --testsuite=Integration