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

Sphinx Bundle Laravel Package

chebur/sphinx-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require chebur/sphinx-bundle
    

    Add to config/bundles.php (Symfony 4+) or register in AppKernel.php (Symfony 3-):

    new Chebur\SphinxBundle\CheburSphinxBundle(),
    
  2. Configuration Define Sphinx server settings in config/packages/chebur_sphinx.yaml:

    chebur_sphinx:
        servers:
            default:
                host: '127.0.0.1'
                port: 9306
                indexer_port: 9312
                timeout: 5.0
    
  3. First Query Inject SphinxClient via dependency injection:

    use Chebur\SphinxBundle\Client\SphinxClient;
    
    public function __construct(SphinxClient $sphinxClient) {
        $this->sphinxClient = $sphinxClient;
    }
    

    Execute a basic search:

    $results = $this->sphinxClient->query('search_term', 'index_name');
    

Implementation Patterns

Core Workflows

  1. Search Integration Use SphinxClient for full-text searches:

    $results = $this->sphinxClient->query('query', 'index_name', [
        'mode' => \SphinxClient::SPH_MATCH_EXTENDED2,
        'limit' => 10,
    ]);
    
  2. Index Management Leverage commands for index operations:

    php bin/console chebur:sphinx:index --index=your_index --action=build
    

    Programmatically via SphinxClient:

    $this->sphinxClient->index('your_index')->build();
    
  3. Query Filtering Apply filters using SphinxQL:

    $results = $this->sphinxClient->query(
        'SELECT * FROM index_name WHERE MATCH(\'query\') AND price > 100'
    );
    
  4. Result Processing Iterate over results:

    foreach ($results as $result) {
        echo $result['id'] . ': ' . $result['weight'] . "\n";
    }
    

Integration Tips

  • Symfony Forms: Bind Sphinx results to form fields for faceted search.
  • API Layer: Expose Sphinx queries via API controllers with DTOs.
  • Caching: Cache frequent queries using Symfony’s cache system.
  • Event Listeners: Hook into kernel.terminate to log Sphinx query times.

Gotchas and Tips

Common Pitfalls

  1. Connection Issues

    • Ensure Sphinx server is running (sudo service sphinxsearch start).
    • Verify host/port in config match your Sphinx setup.
  2. Index Not Found

    • Check index names in sphinx.conf and rebuild if needed:
      php bin/console chebur:sphinx:index --index=your_index --action=build
      
  3. Query Timeouts

    • Increase timeout in config or optimize queries (avoid wildcards, use filters).
  4. Deprecated Methods

    • The bundle is outdated (last release 2019). Prefer direct sphinxapi usage if needed:
      $client = new \Sphinx\Client();
      $client->SetServer('127.0.0.1', 9306);
      

Debugging Tips

  • Enable Profiling: Use the chebur:sphinx:profile command to log query performance.
  • Check Logs: Enable Sphinx logging in sphinx.conf for server-side errors.
  • Test Queries: Validate queries with sphinxsearch CLI before integrating.

Extension Points

  1. Custom Clients Extend SphinxClient for project-specific logic:

    class CustomSphinxClient extends \Chebur\SphinxBundle\Client\SphinxClient {
        public function customQuery($query) { ... }
    }
    
  2. Event Dispatchers Dispatch events for index operations (e.g., sphinx.index.build.start).

  3. Configuration Overrides Override defaults in config/packages/chebur_sphinx.yaml:

    chebur_sphinx:
        servers:
            custom:
                host: '%env(SPHINX_HOST)%'
                # ...
    
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.
croct/coding-standard
croct/plug-php
nqxcode/phpmorphy
boundwize/pyrameter
testo/facade
headercat/phpstan-extension-ide-helper
yosymfony/parser-utils
innmind/black-box
babenkoivan/elastic-migrations
babenkoivan/elastic-adapter
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle