PHP code example of ritey / laravel-manticore

1. Go to this page and download the library: Download ritey/laravel-manticore 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/ */

    

ritey / laravel-manticore example snippets


'driver' => 'manticore',

use Laravel\Scout\Searchable;

class Post extends Model
{
    use Searchable;

    public function searchableAs(): string
    {
        return 'posts_index';
    }

    public function toSearchableArray(): array
    {
        return [
            'title' => $this->title,
            'body' => $this->body,
            'metadata' => $this->metadata,
            'embedding' => $this->embedding,
        ];
    }
}

Post::search('open education')->get();

use Ritey\LaravelManticore\FilterBuilder;

$filters = (new FilterBuilder)
    ->where('metadata.topic', 'ai')
    ->whereRange('score', ['gte' => 0.6]);

Post::search('ai in education')
    ->tap(function ($builder) use ($filters, $vector) {
        $builder->vector = $vector;
        $builder->filterBuilder = $filters;
        $builder->similarity = 'cosine';
    })
    ->get();

Post::search('ai')
    ->tap(fn($b) => $b->sort = [['score' => 'desc']])
    ->get();

Post::search('language learning')
    ->tap(fn($b) => $b->boosts = ['title' => 2.0, 'body' => 1.0])
    ->get();

Post::search('climate')
    ->tap(fn($b) => $b->facets = ['metadata.topic'])
    ->get();

use Laravel\Scout\EngineManager;

$engine = resolve(EngineManager::class)->engine('manticore');
$engine->createIndex('posts_index');
$engine->deleteIndex('posts_index');
bash
php artisan vendor:publish --tag=config
bash
php artisan manticore:create-index "App\Models\Post"
bash
php artisan manticore:sync-index "App\Models\Post"