camdram/sphinx-realtime-bundle
Installation Add the bundle to your Symfony2 project via Composer:
composer require camdram/sphinx-realtime-bundle
Enable the bundle in app/AppKernel.php:
new Camdram\SphinxRealtimeBundle\CamdramSphinxRealtimeBundle(),
Configuration
Configure Sphinx connection in app/config/config.yml:
sphinx_realtime:
client:
host: 127.0.0.1
port: 9312
path: /var/run/sphinx/sphinx.sock # Optional, for Unix sockets
index: your_index_name
First Use Case: Indexing an Entity
Annotate your Doctrine entity with @Sphinx\Index:
use Camdram\SphinxRealtimeBundle\Bridge\Doctrine\Sphinx\Index;
/**
* @Index(index="your_index_name", delta="your_delta_name")
*/
class Product
{
// ...
}
Run the initial sync:
php app/console sphinx:realtime:sync
Automatic Sync
The bundle hooks into Doctrine lifecycle events (postPersist, postUpdate, postRemove) to auto-sync entities. No manual intervention required for CRUD operations.
Delta Indexing Use delta indexes for real-time updates:
# app/config/config.yml
sphinx_realtime:
client:
host: 127.0.0.1
index: main_index
delta_index: delta_index # Optional delta config
Custom Mappings Override default field mappings via annotations:
/**
* @Index(
* fields={
* "name"="title",
* "description"="content"
* }
* )
*/
class Article { ... }
Querying
Use the SphinxRealtimeClient service to query:
$client = $this->get('sphinx_realtime.client');
$results = $client->query('search_term');
sphinx.realtime.sync events.php app/console sphinx:realtime:sync --batch-size=100.$em->getEventManager()->removeEventListeners('postPersist');
Delta Index Mismatch
Ensure delta_index in config matches the @Index(delta="...") annotation. Mismatches cause silent failures.
Connection Issues Sphinx client may hang if the server is unreachable. Add retry logic:
sphinx_realtime:
client:
timeout: 5
retries: 3
Field Type Conflicts
Sphinx expects specific field types (e.g., INT64 for IDs). Annotate explicitly:
/**
* @Index(fields={
* "id"="id INT64"
* })
*/
Circular References Avoid bidirectional associations in indexed entities to prevent infinite loops during sync.
Enable Logging: Add to config.yml:
sphinx_realtime:
debug: true
Logs appear in var/log/dev.log.
Check Sync Status:
php app/console sphinx:realtime:status
Custom Sync Logic
Override the Camdram\SphinxRealtimeBundle\Sync\SyncManager service to add pre/post-sync hooks.
Custom Field Transformers
Implement Camdram\SphinxRealtimeBundle\Sync\FieldTransformerInterface for custom field formatting.
Async Sync Use Symfony’s Messenger component to queue syncs for high-traffic apps:
sphinx_realtime:
async: true
How can I help you explore Laravel packages today?