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

agentsib/sphinx-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require agentsib/sphinx-bundle
    

    Ensure your composer.json targets Symfony 2.3+ (as per requirements).

  2. Configuration Add the bundle to AppKernel.php:

    new Agentsib\SphinxBundle\AgentsibSphinxBundle(),
    

    Configure Sphinx connection in config.yml:

    agentsib_sphinx:
        connections:
            default:
                host:     '127.0.0.1'
                port:     9306
                index:    'your_index_name'
                weight:   1000
    
  3. First Query Inject the SphinxManager service and run a basic query:

    use Agentsib\SphinxBundle\Manager\SphinxManager;
    
    class SearchController extends Controller
    {
        public function search(SphinxManager $sphinx)
        {
            $results = $sphinx->query('your_search_term');
            return $this->render('search/results.html.twig', ['results' => $results]);
        }
    }
    

Key Files to Review

  • Resources/config/services.yml (Service definitions)
  • DependencyInjection/Configuration.php (Bundle configuration schema)
  • Manager/SphinxManager.php (Core query logic)

Implementation Patterns

Query Building

Leverage foolz/sphinxql-query-builder for complex queries:

$query = $sphinx->createQueryBuilder()
    ->select('id, title, content')
    ->from('your_index')
    ->where('MATCH(@title)')->equals('search_term')
    ->limit(10);

$results = $sphinx->query($query);

Integration with Symfony Forms

Bind search results to form fields dynamically:

$form = $this->createFormBuilder()
    ->add('query', TextType::class, [
        'data' => $request->query->get('q'),
    ])
    ->getForm();

Pagination

Use KnpPaginatorBundle alongside Sphinx:

use Knp\Component\Pager\PaginatorInterface;

public function paginatedSearch(SphinxManager $sphinx, PaginatorInterface $paginator)
{
    $results = $sphinx->query('term', 10, ($page-1)*10);
    $pagination = $paginator->paginate(
        $results,
        $page,
        10
    );
}

Caching Results

Cache frequent queries with Symfony Cache component:

$cache = $this->get('cache.app');
$cacheKey = 'sphinx_results_' . md5('term');
$results = $cache->get($cacheKey, function() use ($sphinx) {
    return $sphinx->query('term');
});

Gotchas and Tips

Common Pitfalls

  1. Index Mismatch Ensure the configured index in config.yml matches your Sphinx index name. Test with:

    sphinxql -h 127.0.0.1 -P 9306 -Q "SHOW INDEXES"
    
  2. Query Builder Syntax The foolz/sphinxql-query-builder may differ from native SphinxQL. Validate queries with:

    $query->getSQL(); // Outputs raw SphinxQL
    
  3. Dependency Conflicts Symfony 2.3+ is required. Avoid mixing with newer Symfony versions without patching.

Debugging

  • Enable Sphinx Logging Add to config.yml:

    agentsib_sphinx:
        debug: true
    

    Logs appear in var/log/dev.log.

  • Query Profiling Use XHProf or Sphinx’s built-in profiling:

    $sphinx->setDebug(true);
    $results = $sphinx->query('term');
    

Extension Points

  1. Custom Query Handlers Extend SphinxManager to add methods for domain-specific queries:

    class CustomSphinxManager extends SphinxManager
    {
        public function searchProducts($term)
        {
            return $this->query("SELECT * FROM products WHERE MATCH('@title') = '$term'");
        }
    }
    
  2. Event Listeners Subscribe to agentsib_sphinx.query events for pre/post-query logic:

    services:
        app.sphinx_listener:
            class: AppBundle\EventListener\SphinxListener
            tags:
                - { name: kernel.event_listener, event: agentsib_sphinx.query, method: onQuery }
    
  3. Async Search Use Symfony Messenger to offload heavy queries:

    $message = new SphinxSearchMessage('term');
    $this->get('messenger')->dispatch($message);
    

Configuration Quirks

  • Weight Adjustment Modify weight in config.yml to balance Sphinx vs. other search backends (e.g., Elasticsearch).
  • Connection Fallback Define multiple connections for redundancy:
    connections:
        primary:
            host: '127.0.0.1'
        backup:
            host: '10.0.0.1'
            weight: 100
    
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.
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
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle