Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Meilisearch Php Laravel Package

meilisearch/meilisearch-php

Official PHP client for Meilisearch, the open‑source search engine. Connect to Meilisearch or Meilisearch Cloud to index documents, configure indexes, and run fast, typo‑tolerant searches. Supports customizable HTTP clients and common PHP tooling.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Search-Centric Use Case: The package is a near-perfect fit for Laravel applications requiring fast, typo-tolerant, and customizable search (e.g., e-commerce product catalogs, documentation search, or user-generated content). Meilisearch’s vector search (via extensions) and real-time indexing align well with Laravel’s event-driven architecture.
  • Decoupled Design: The PHP SDK abstracts Meilisearch’s REST API, allowing seamless integration without tight coupling to Laravel’s ORM (Eloquent). This enables hybrid search (e.g., SQL for structured queries + Meilisearch for full-text).
  • Event-Driven Synergy: Meilisearch’s asynchronous indexing (via tasks) pairs well with Laravel’s queues (e.g., addDocuments() can trigger a job to update search indexes post-Eloquent create()/update()).

Integration Feasibility

  • Low Friction: The SDK is PSR-18 compliant, requiring minimal setup (e.g., Guzzle/Symfony HTTP client). Laravel’s built-in HTTP clients (e.g., HttpClient) can be adapted with minimal boilerplate.
  • Service Provider Pattern: The package can be wrapped in a Laravel service provider to centralize configuration (e.g., Meilisearch URL, API key, retry logic) and bind the client as a singleton.
  • Eloquent Integration: Can extend Eloquent models with searchable traits or observers to auto-index changes (e.g., Model::saved()Meilisearch::updateDocuments()).

Technical Risk

  • Version Alignment: The SDK guarantees compatibility with Meilisearch v1.x, but v2.x breaking changes (e.g., typed queries) may require future updates. Monitor Meilisearch’s roadmap for API deprecations.
  • Cold Starts: Meilisearch’s local-first indexing (vs. cloud-managed) may introduce latency if self-hosted. Mitigate with caching (e.g., Laravel’s cache() facade) or Meilisearch Cloud.
  • Schema Mismatches: Laravel’s Eloquent schemas (e.g., belongsTo) may not map cleanly to Meilisearch’s flat document structure. Requires normalization (e.g., JSON fields for relationships).
  • Rate Limiting: Self-hosted Meilisearch may throttle requests under load. Configure queue retries or exponential backoff in the SDK.

Key Questions

  1. Hosting Strategy:
    • Self-hosted (e.g., Docker) vs. Meilisearch Cloud? Cloud reduces ops overhead but may introduce vendor lock-in.
  2. Data Sync:
    • How to handle conflicts between Eloquent and Meilisearch (e.g., soft-deletes, optimistic locking)?
  3. Performance:
    • What’s the expected query volume? For high traffic, consider sharding or dedicated Meilisearch instances.
  4. Fallback:
    • Should the app degrade gracefully (e.g., return SQL results) if Meilisearch fails?
  5. Cost:
    • For cloud, estimate storage/bandwidth costs based on document size and query volume.

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • HTTP Clients: Use Laravel’s HttpClient (PSR-18 compliant) or Guzzle for flexibility.
    • Queues: Offload addDocuments()/updateDocuments() to Laravel queues (e.g., meilisearch:update-index) for async indexing.
    • Caching: Cache search results (e.g., Cache::remember()) to reduce Meilisearch load.
    • Testing: Use Laravel’s HttpClient mocking or PestPHP to test Meilisearch interactions.
  • Database Synergy:
    • Hybrid Search: Use Eloquent for structured queries (e.g., WHERE category_id = 1) and Meilisearch for full-text (e.g., title: "action").
    • Migrations: Add a searchable column to track Meilisearch document IDs for sync.

Migration Path

  1. Phase 1: Pilot Index
    • Start with a non-critical index (e.g., blog posts) to test performance and sync logic.
    • Use Meilisearch’s addDocuments() with a one-time dump of existing data (e.g., from Eloquent).
  2. Phase 2: Real-Time Sync
    • Implement Eloquent observers or model events to sync changes to Meilisearch.
    • Example:
      // app/Observers/PostObserver.php
      public function saved(Post $post) {
          Meilisearch::index('posts')->updateDocuments([$post->toSearchableArray()]);
      }
      
  3. Phase 3: Query Replacement
    • Replace legacy DB::select() or Algolia queries with Meilisearch SDK calls.
    • Example:
      // Replace: DB::select("SELECT * FROM posts WHERE title LIKE '%action%'")
      $hits = Meilisearch::index('posts')->search('action')->getHits();
      

Compatibility

  • Laravel Versions: Compatible with Laravel 8+ (PHP 8.0+). Test with Laravel 10 for PHP 8.2 features.
  • Meilisearch Features:
    • Typo Tolerance: Enable via typoTolerance: 'min' in index settings.
    • Filters: Use filterableAttributes for faceted search (e.g., genres = "Action").
    • Ranking: Customize with rankingRules (e.g., prioritize recent posts).
  • Fallback: Implement a circuit breaker (e.g., Spatie’s CircuitBreaker) to fall back to SQL if Meilisearch fails.

Sequencing

  1. Setup:
    • Install SDK + HTTP client: composer require meilisearch/meilisearch-php guzzlehttp/guzzle.
    • Configure in config/services.php:
      'meilisearch' => [
          'url' => env('MEILISEARCH_URL', 'http://localhost:7700'),
          'api_key' => env('MEILISEARCH_API_KEY'),
          'timeout' => 5.0,
      ],
      
  2. Service Provider:
    • Bind the client in AppServiceProvider:
      $this->app->singleton(Meilisearch\Client::class, function ($app) {
          return new Meilisearch\Client(
              config('services.meilisearch.url'),
              config('services.meilisearch.api_key')
          );
      });
      
  3. Index Initialization:
    • Create indexes via Laravel console commands (e.g., php artisan meilisearch:create-index posts).
  4. Sync Data:
    • Write a queue job to bulk-import existing data:
      // app/Jobs/ImportToMeilisearch.php
      public function handle() {
          $posts = Post::all()->toSearchableArray();
          Meilisearch::index('posts')->addDocuments($posts);
      }
      

Operational Impact

Maintenance

  • Schema Drift:
    • Monitor for Meilisearch API changes (e.g., new search parameters). Update the SDK and test.
    • Use migrations to update index settings (e.g., updateSearchableAttributes).
  • Documentation:
    • Add internal docs for:
      • Index naming conventions (e.g., products_*).
      • Sync workflows (e.g., "How to handle deleted Eloquent models").
      • Performance tuning (e.g., "When to use distinct in federated search").
  • Dependency Updates:
    • Pin SDK version in composer.json to avoid breaking changes (e.g., meilisearch/meilisearch-php:^2.0).

Support

  • Debugging:
    • Log Meilisearch task IDs for async operations to track failures:
      $task = $index->addDocuments($documents);
      logger()->info("Meilisearch task ID: {$task->uid()}");
      
    • Use getTask() to check status:
      $task = $client->getTask($taskId);
      if ($task->status() === 'failed') {
          throw new \RuntimeException("Meilisearch task failed: " . $task->error());
      }
      
  • Common Issues:
    • Timeouts: Increase timeout in the client config for slow networks.
    • Permission Errors: Ensure API keys have correct actions (e.g., documents:*).
    • Data Mismatches: Validate toSearchableArray() output matches Meilisearch’s schema.

Scaling

  • Horizontal Scaling:
    • Meilisearch: Scale by adding more instances (shard data by index prefix, e.g., products_a, products_b).
    • **L
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui