### Install Laravel Manticore Eloquent Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Install the package using Composer. This command adds the necessary files to your project. ```bash composer require renatomaldonado/laravel-manticore-eloquent ``` -------------------------------- ### Run Local Manticore Instance with Docker Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Start a local Manticore Search server using Docker. This command maps the default Manticore ports (9306 for MySQL, 9308 for HTTP) to your host machine. ```bash docker run --name manticore -p 9306:9306 -p 9308:9308 manticoresearch/manticore ``` -------------------------------- ### Generate Test Coverage Report Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Generate a full test coverage report or fail the build if coverage drops below 95%. Requires PCOV or Xdebug to be installed. ```bash composer test:coverage # full report composer test:coverage-min # fails under 95% ``` -------------------------------- ### Run Full Test Coverage Report Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/docs/ARCHITECTURE.md Execute this command to generate a full code coverage report for the project. This requires a configured testing environment. ```bash composer test:coverage ``` -------------------------------- ### Publish Configuration File Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Publish the package's configuration file to your project. This allows for customization of Manticore connection settings. ```bash php artisan vendor:publish --provider="ManticoreEloquent\ManticoreEloquentServiceProvider" --tag=config ``` -------------------------------- ### Configure Manticore Connection Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Configure the Manticore connection details in the `config/manticore-eloquent.php` file or via environment variables. This includes host, port, username, and password. ```php 'connection' => env('MANTICORE_CONNECTION', 'manticore'), 'host' => env('MANTICORE_HOST', '127.0.0.1'), 'port' => env('MANTICORE_PORT', 9306), // MySQL protocol port 'username' => env('MANTICORE_USERNAME'), 'password' => env('MANTICORE_PASSWORD'), 'engine' => env('MANTICORE_ENGINE'), // 'columnar' | 'rowwise' | null ``` -------------------------------- ### Project Structure Overview Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/docs/ARCHITECTURE.md This snippet shows the directory structure of the Laravel Manticore Eloquent package, highlighting the key files and their roles in the architecture. ```text src/ ├── ManticoreEloquentServiceProvider.php — registers the driver, connection and schema macros ├── Concerns/HasManticore.php — trait: Model::manticore() gateway ├── Eloquent/ManticoreModel.php — base model whose default connection is Manticore └── Database/ ├── ManticoreConnector.php — PDO (MySQL) without the incompatible SETs; emulated prepares ├── ManticoreConnection.php — MySqlConnection + its own grammar/schema/processor/query ├── Query/ │ ├── ManticoreQueryBuilder.php — match/knn/highlight/option/maxMatches/facet/replace │ ├── Grammars/ManticoreQueryGrammar.php — MATCH(?), knn(), HIGHLIGHT(), OPTION, FACET, REPLACE, no lock │ └── Processors/ManticoreProcessor.php └── Schema/ ├── ManticoreSchemaGrammar.php — CREATE/ALTER/DROP TABLE with Manticore types └── ManticoreSchemaBuilder.php — hasTable/getColumnListing via SHOW TABLES/DESC ``` -------------------------------- ### Run Minimum Test Coverage Report Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/docs/ARCHITECTURE.md Use this command to run the test coverage report and fail if coverage drops below 95%. This is useful for CI/CD pipelines to enforce a minimum coverage threshold. ```bash composer test:coverage-min ``` -------------------------------- ### Highlighting Search Results Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Enable highlighting for search results to visually indicate matching terms within specified fields. The highlight method configures the markup to be used around matched terms, and the results will include a 'highlight' column. ```php Article::manticore() ->match('cloud native') ->highlight('body', ['before_match' => '', 'after_match' => '']) ->get(); // each row gets a `highlight` column (alias configurable) ``` -------------------------------- ### Relational Model with Manticore Integration Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Integrate Manticore search into a standard Eloquent model using the HasManticore trait. This allows querying both the relational database and Manticore indexes. Specify the Manticore index name using the searchableAs method. ```php use Illuminate\Database\Eloquent\Model; use ManticoreEloquent\Concerns\HasManticore; class Company extends Model { use HasManticore; public function searchableAs(): string { return 'companies_rt'; // Manticore index name } } Company::query()->where('id', 1)->first(); // relational DB Company::manticore()->match('fintech')->paginate(); // Manticore ``` -------------------------------- ### Advanced Manticore Querying Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Utilize Manticore-specific helper methods for advanced search queries, including full-text matching with field targeting, filtering, ranking options, and faceting. These methods translate directly to Manticore query syntax. ```php Article::manticore() ->match('cloud native', 'title') // MATCH('@title cloud native') ->where('views', '>', 100) ->option('ranker', 'sph04') // OPTION ranker=sph04 ->maxMatches(5000) // OPTION max_matches=5000 ->facet('category') // FACET category ->get(); ``` ```php Article::manticore()->replace(['id' => 1, 'title' => 'New', 'body' => '…']); ``` -------------------------------- ### Run Offline and Integration Tests Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Execute offline unit and feature tests using Pest. For integration tests, ensure Manticore is running on the configured MySQL port and set the MANTICORE_HOST and MANTICORE_PORT environment variables if necessary. ```bash composer install vendor/bin/pest --testsuite=Unit,Feature # offline tests (no server needed) # Integration tests require a running Manticore on the configured MySQL port # (defaults to 9306; override with MANTICORE_HOST / MANTICORE_PORT): MANTICORE_HOST=127.0.0.1 MANTICORE_PORT=9306 vendor/bin/pest --testsuite=Integration ``` -------------------------------- ### KNN Vector Search Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Perform K-Nearest Neighbors (KNN) vector search on a floatVector column. Requires the column to be defined as floatVector in the migration. Use knn_dist() to retrieve the similarity score. ```php // knn(`embedding`, 10, (0.12, 0.98, …)) — pair with knn_dist() to read the score Article::manticore() ->knn('embedding', $queryVector, k: 10) // optional ef: ->knn(..., ef: 2000) ->selectRaw('*, knn_dist() as distance') ->get(); ``` -------------------------------- ### Create Manticore Real-time Index with Laravel Migration Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Defines a Manticore real-time index named 'articles_rt' using Laravel's Schema builder. This snippet illustrates various Manticore column types like text, string, integer, bigint, float, boolean, json, timestamp, mva, mva64, and floatVector, along with Manticore-specific table options such as minInfixLen and morphology. ```php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { public function up(): void { Schema::connection('manticore')->create('articles_rt', function (Blueprint $table) { // `id` is implicit in Manticore — no need to declare it. $table->text('body'); // text (full-text indexed) $table->string('title'); // string attribute $table->integer('views'); // integer $table->bigInteger('author_id'); // bigint $table->float('score'); // float $table->boolean('published'); // bool $table->json('meta'); // json $table->timestamp('created_at'); // timestamp $table->mva('tag_ids'); // multi (uint set) $table->mva64('big_ids'); // multi64 $table->floatVector('embedding', dims: 384); // float_vector for KNN $table->text('summary')->indexed()->stored();// spell out text options // Table-level Manticore options (trailing key='value' on CREATE TABLE) $table->minInfixLen(2); // infix search $table->morphology('stem_en'); // or ->manticoreOptions([...]) // $table->engine = 'columnar'; }); } public function down(): void { Schema::connection('manticore')->dropIfExists('articles_rt'); } }; ``` -------------------------------- ### Manticore-Only Model Definition Source: https://github.com/renato27/laravel-manticore-eloquent/blob/master/README.md Define a model that exclusively uses Manticore by extending ManticoreModel. This is suitable when your data primarily resides in Manticore. Ensure the connection is set to Manticore. ```php use ManticoreEloquent\Eloquent\ManticoreModel; class Article extends ManticoreModel { protected $table = 'articles_rt'; protected $guarded = []; protected $casts = ['published' => 'boolean', 'created_at' => 'datetime']; } Article::where('published', true)->match('laravel')->orderBy('created_at', 'desc')->paginate(); Article::find(10); Article::create(['title' => 'Hello', 'body' => '…', 'published' => true]); Article::where('id', 10)->update(['published' => false]); Article::destroy(10); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.