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

Typesense Php Laravel Package

typesense/typesense-php

Official PHP client for the Typesense search API. Install via Composer with an HTTPlug-compatible HTTP client, then manage collections, documents, and searches using the Typesense server API. Includes examples and safe filter string escaping.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Search Layer Integration: The typesense/typesense-php package is a highly specialized client for Typesense, a fast open-source search engine. It aligns perfectly with Laravel applications requiring real-time search, autocomplete, or faceted search capabilities without relying on Elasticsearch or Algolia.
  • API Abstraction: The package abstracts Typesense’s REST API, reducing boilerplate for CRUD operations (collections, documents, aliases) and advanced features (filtering, ranking, synonyms, and natural language search).
  • Laravel Synergy: Works seamlessly with Laravel’s dependency injection (via HttpClient or Guzzle) and integrates with Laravel’s caching (e.g., caching search results via Cache facade).

Integration Feasibility

  • HTTP Client Flexibility: Supports HTTPlug (e.g., Guzzle, Symfony HTTP Client, or PHP-HTTP clients), making it adaptable to Laravel’s built-in Http or third-party clients.
  • Laravel Service Provider: Can be bootstrapped via a Laravel Service Provider to centralize configuration (e.g., API keys, endpoints, retries).
  • Query Builder: Provides a fluent interface for constructing complex queries (e.g., filter_by, query_by, group_by), reducing SQL-like query syntax complexity.

Technical Risk

  • Version Alignment: Critical risk if the Laravel app uses an older Typesense server (<v30.0). The package enforces strict version compatibility (e.g., v6.x requires Typesense ≥v30.0). A migration plan is needed if upgrading Typesense.
  • Breaking Changes: v6.0.0 introduced breaking changes for Typesense v30.0 (e.g., API endpoint deprecations). Audit existing queries for deprecated methods (e.g., multiSearch type changes).
  • HTTPlug Dependency: Requires an HTTPlug-compatible client (e.g., php-http/curl-client). Laravel’s native Http client may need a wrapper or adapter.
  • Error Handling: Custom exceptions (e.g., Typesense\Exceptions\TypesenseException) must be mapped to Laravel’s exception handler for consistent logging/alerting.

Key Questions

  1. Typesense Server Version: Is the target Typesense server ≥v30.0? If not, can we upgrade, or must we pin to v5.x?
  2. HTTP Client Strategy: Will we use Laravel’s Http client, Guzzle, or another HTTPlug adapter? Does the team have experience with HTTPlug?
  3. Query Complexity: Are there highly customized queries (e.g., nested filters, custom ranking) that might require extending the client?
  4. Performance: Will search queries be cached (e.g., via Laravel’s cache or Redis)? How will we handle rate limiting or retries?
  5. Monitoring: How will we log/search failures (e.g., 500 errors, timeouts)? The package supports custom loggers—should we integrate with Laravel’s Log facade?
  6. Testing: Are there existing PHPUnit tests for Typesense interactions? Should we mock the client for unit tests or use a local Typesense instance?

Integration Approach

Stack Fit

  • Laravel Ecosystem: The package is PHP-first and integrates natively with:
    • Laravel’s Http client (via HTTPlug adapter like php-http/guzzle7-adapter).
    • Laravel’s caching (e.g., cache search results or schema metadata).
    • Laravel’s queues (e.g., async document indexing via bus:dispatch).
    • Laravel’s Scout (if migrating from Scout to Typesense).
  • Alternatives: If using Lumen or non-Laravel PHP, the integration is still viable but requires manual DI setup.

Migration Path

  1. Assessment Phase:
    • Audit existing search queries (Elasticsearch/Algolia/Scout) for Typesense compatibility.
    • Identify custom logic (e.g., post-processing results) that may need adaptation.
  2. Dependency Setup:
    composer require typesense/typesense-php php-http/curl-client
    
    Or for Laravel’s Http client:
    composer require typesense/typesense-php php-http/guzzle7-adapter
    
  3. Configuration:
    • Create a Laravel config file (config/typesense.php) for API keys, endpoints, and retries.
    • Example:
      return [
          'api_key' => env('TYPESENSE_API_KEY'),
          'nodes' => [
              ['host' => env('TYPESENSE_HOST', 'localhost'), 'port' => env('TYPESENSE_PORT', 8108), 'protocol' => 'http'],
          ],
          'connection_timeout_seconds' => 5,
          'read_timeout_seconds' => 10,
          'retries' => 3,
      ];
      
  4. Service Provider:
    • Bind the client to Laravel’s container:
      public function register()
      {
          $this->app->singleton(TypesenseClient::class, function ($app) {
              $config = $app['config']['typesense'];
              return new TypesenseClient([
                  'nodes' => $config['nodes'],
                  'api_key' => $config['api_key'],
                  'connection_timeout_seconds' => $config['connection_timeout_seconds'],
                  'read_timeout_seconds' => $config['read_timeout_seconds'],
                  'retries' => $config['retries'],
                  'http_client' => $app->make(HttpClient::class), // Laravel's Http client
              ]);
          });
      }
      
  5. Query Migration:
    • Replace existing search logic with the client’s methods. Example:
      // Old (e.g., Scout/Elasticsearch)
      $results = Search::query($query)->get();
      
      // New (Typesense)
      $client = app(TypesenseClient::class);
      $searchResults = $client->collections('products')
          ->documents()
          ->search('query=' . urlencode($query))
          ->with ties-breaker()
          ->with filter_by('price > 100')
          ->get();
      
  6. Testing:
    • Use mocking (e.g., Mockery) for unit tests or a local Typesense Docker instance for integration tests.
    • Example test setup:
      docker run -p 8108:8108 -p 8109:8109 typesense/typesense:latest
      

Compatibility

  • Laravel Versions: Tested with Laravel 10+ (v4.8.2+). For older Laravel, use v4.x of the package.
  • Typesense Features: Supports all Typesense v30+ features (e.g., NL search, schema changes, analytics). For older Typesense, downgrade the package.
  • Edge Cases:
    • Special characters in queries: Use FilterBy::escapeString() to prevent injection.
    • Large payloads: Stream responses for bulk operations (e.g., documents()->import()).

Sequencing

  1. Phase 1: Replace simple searches (e.g., search() calls) with the client.
  2. Phase 2: Migrate complex queries (e.g., faceted search, aggregations).
  3. Phase 3: Optimize performance (caching, retries, async indexing).
  4. Phase 4: Deprecate old search logic and update documentation.

Operational Impact

Maintenance

  • Dependency Updates: Monitor Typesense server and PHP client versions for breaking changes (e.g., v6.x for Typesense v30+).
  • Logging: Leverage the client’s custom logger to integrate with Laravel’s Log facade or a monitoring tool (e.g., Sentry).
  • Backups: Typesense data is stored in collections. Implement a backup strategy (e.g., export schemas/documents via the API).

Support

  • Troubleshooting:
    • Use Typesense\Exceptions\TypesenseException to catch API errors.
    • Enable debug mode in the client for verbose logging:
      $client->setDebug(true);
      
  • Community: Active GitHub repo with responsive maintainers (Typesense team). Issues are typically resolved within days.
  • Laravel-Specific: Limited Laravel-specific support; may need to extend the client for custom use cases.

Scaling

  • Horizontal Scaling: Typesense supports multi-node clusters. Configure the client with multiple nodes for high availability:
    $client = new TypesenseClient([
        'nodes' => [
            ['host' => 'typesense1', 'port' => 8108],
            ['host' => 'typesense2', 'port' => 8108],
        ],
        // ...
    ]);
    
  • **Performance Tun
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.
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
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament