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 an ideal fit for Laravel applications requiring fast, typo-tolerant, and flexible search (e.g., e-commerce product catalogs, content management systems, or internal tools with complex filtering).
  • Decoupled Design: Meilisearch operates independently of the application, reducing coupling and enabling horizontal scaling of search workloads.
  • Eventual Consistency: Asynchronous indexing (via tasks) aligns with Laravel’s queue-based background job patterns (e.g., addDocuments() can be dispatched to a queue).
  • Alternatives Comparison:
    • vs. Laravel Scout: Meilisearch offers real-time indexing, typo tolerance, and advanced filtering out of the box, whereas Scout requires additional drivers (e.g., Algolia) for similar features.
    • vs. Elasticsearch: Lower operational overhead (no sharding/cluster management) and simpler setup, though Elasticsearch offers more advanced analytics.

Integration Feasibility

  • Laravel Ecosystem Compatibility:
    • Service Providers: Can be bootstrapped via Laravel’s ServiceProvider (e.g., bind Meilisearch\Client to the container).
    • Configuration: Supports .env integration (e.g., MEILI_HOST, MEILI_API_KEY).
    • Queue Integration: Asynchronous operations (e.g., addDocuments()) can leverage Laravel’s queue system.
    • Caching: Results can be cached using Laravel’s cache layer (e.g., Cache::remember()).
  • Database Agnostic: Works with any data source (MySQL, PostgreSQL, etc.) since it indexes documents via API calls.
  • Real-Time Updates: Supports webhooks (via Meilisearch’s API) to trigger Laravel events on index changes.

Technical Risk

Risk Area Mitigation Strategy
API Versioning Monitor Meilisearch’s roadmap for breaking changes. Use semantic versioning in Laravel’s composer.json.
Performance Benchmark indexing/search latency under production load. Consider index sharding for large datasets.
Error Handling Wrap Meilisearch API calls in Laravel’s try/catch and log errors via Log::error().
Dependency Bloat Only install required HTTP clients (e.g., guzzlehttp/guzzle) to avoid unnecessary dependencies.
Self-Hosting vs. Cloud Evaluate Meilisearch Cloud for managed hosting or self-host for compliance/control.

Key Questions

  1. Data Volume: How large is the dataset? (Meilisearch handles millions of documents but may require tuning for 10M+.)
  2. Real-Time Needs: Does the app need sub-second latency for searches? (Meilisearch typically achieves <50ms for indexed data.)
  3. Filtering Complexity: Are there nested filters or geospatial queries? (Meilisearch supports advanced filtering.)
  4. Fallback Strategy: Should the app degrade gracefully if Meilisearch is unavailable? (Cache frequent queries or use a backup search provider.)
  5. Cost: For Meilisearch Cloud, estimate usage based on pricing (e.g., 100k searches/month = ~$20).

Integration Approach

Stack Fit

  • Laravel 8+: Fully compatible with PHP 8.0+ and PSR-18 HTTP clients.
  • HTTP Clients:
    • Recommended: guzzlehttp/guzzle (most mature, widely used).
    • Alternatives: symfony/http-client, php-http/curl-client (if Guzzle is avoided).
  • Queue Integration:
    • Dispatch addDocuments() to Laravel’s queue (e.g., bus:queue) for async indexing.
    • Example:
      use Meilisearch\Client;
      use Illuminate\Support\Facades\Bus;
      
      Bus::dispatch(function () {
          $client->index('products')->addDocuments($newProducts);
      });
      
  • Caching Layer:
    • Cache search results with Cache::remember() or use Laravel’s Cache::tags() for invalidation.
    • Example:
      $results = Cache::remember("meili_search_{$query}", now()->addMinutes(5), function () use ($index, $query) {
          return $index->search($query)->getHits();
      });
      

Migration Path

  1. Phase 1: Proof of Concept (PoC)
    • Set up a local Meilisearch instance (docker run -p 7700:7700 getmeili/meilisearch:v1.3).
    • Replace a simple Laravel query (e.g., DB::table('products')->where(...)) with Meilisearch.
    • Example:
      // Before: Database query
      $products = Product::where('name', 'like', '%phone%')->get();
      
      // After: Meilisearch
      $hits = $client->index('products')->search('phone')->getHits();
      
  2. Phase 2: Hybrid Search
    • Use Meilisearch for search-heavy queries and fall back to the database for exact matches.
    • Example middleware:
      public function handle(Request $request, Closure $next) {
          if ($request->has('search')) {
              $results = $this->meilisearch->search($request->search);
              return response()->json($results);
          }
          return $next($request);
      }
      
  3. Phase 3: Full Migration
    • Replace all search logic with Meilisearch.
    • Migrate existing data via a Laravel command:
      use Meilisearch\Client;
      use App\Models\Product;
      
      $client = new Client(config('meilisearch.host'), config('meilisearch.key'));
      $index = $client->index('products');
      $index->addDocuments(Product::all()->toArray());
      

Compatibility

  • Laravel Scout: If migrating from Scout, replace ScoutDriver with a custom Meilisearch driver:
    // app/Providers/AppServiceProvider.php
    public function boot() {
        Scout::extend('meilisearch', function ($app) {
            return new MeilisearchScoutDriver($app['meilisearch.client']);
        });
    }
    
  • Existing APIs: Meilisearch’s API mirrors Laravel’s Eloquent conventions (e.g., search() instead of where()).
  • Testing: Use Laravel’s HttpTests to mock Meilisearch responses:
    $this->mock(Meilisearch\Client::class, function ($mock) {
        $mock->shouldReceive('search')->andReturn(['hits' => []]);
    });
    

Sequencing

  1. Infrastructure Setup
    • Deploy Meilisearch (self-hosted or Cloud).
    • Configure Laravel’s .env:
      MEILI_HOST=http://localhost:7700
      MEILI_API_KEY=masterKey
      
  2. Client Initialization
    • Bind the client in Laravel’s AppServiceProvider:
      $this->app->singleton(Meilisearch\Client::class, function ($app) {
          return new Client(
              config('meilisearch.host'),
              config('meilisearch.key'),
              new GuzzleHttp\Client()
          );
      });
      
  3. Index Configuration
    • Define indexes in a Laravel config file (config/meilisearch.php):
      return [
          'indexes' => [
              'products' => [
                  'primaryKey' => 'id',
                  'filterableAttributes' => ['category', 'price_range'],
              ],
          ],
      ];
      
  4. Data Migration
    • Write a Laravel artisan command to seed Meilisearch:
      php artisan meilisearch:seed
      
  5. Feature Rollout
    • Start with search functionality, then add filtering, analytics, and real-time updates.

Operational Impact

Maintenance

  • Meilisearch Updates:
    • Monitor Meilisearch releases and update the PHP client via Composer.
    • Test breaking changes (e.g., v2.x API shifts) in a staging environment.
  • Laravel Integration:
    • Update Laravel’s composer.json to pin the Meilisearch client version:
      "meilisearch/meilisearch-php": "^2.0"
      
  • Logging:
    • Log Meilisearch errors and tasks to Laravel’s single channel:
      try {
          $index->addDocuments($docs);
      } catch (\Exception $e) {
          Log::error("Meilisearch indexing failed: " . $e->getMessage());
      }
      

Support

  • **Troubles
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle