Installation
composer require chebur/sphinx-bundle
Add to config/bundles.php (Symfony 4+) or register in AppKernel.php (Symfony 3-):
new Chebur\SphinxBundle\CheburSphinxBundle(),
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
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');
Search Integration
Use SphinxClient for full-text searches:
$results = $this->sphinxClient->query('query', 'index_name', [
'mode' => \SphinxClient::SPH_MATCH_EXTENDED2,
'limit' => 10,
]);
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();
Query Filtering Apply filters using SphinxQL:
$results = $this->sphinxClient->query(
'SELECT * FROM index_name WHERE MATCH(\'query\') AND price > 100'
);
Result Processing Iterate over results:
foreach ($results as $result) {
echo $result['id'] . ': ' . $result['weight'] . "\n";
}
kernel.terminate to log Sphinx query times.Connection Issues
sudo service sphinxsearch start).host/port in config match your Sphinx setup.Index Not Found
sphinx.conf and rebuild if needed:
php bin/console chebur:sphinx:index --index=your_index --action=build
Query Timeouts
timeout in config or optimize queries (avoid wildcards, use filters).Deprecated Methods
sphinxapi usage if needed:
$client = new \Sphinx\Client();
$client->SetServer('127.0.0.1', 9306);
chebur:sphinx:profile command to log query performance.sphinx.conf for server-side errors.sphinxsearch CLI before integrating.Custom Clients
Extend SphinxClient for project-specific logic:
class CustomSphinxClient extends \Chebur\SphinxBundle\Client\SphinxClient {
public function customQuery($query) { ... }
}
Event Dispatchers
Dispatch events for index operations (e.g., sphinx.index.build.start).
Configuration Overrides
Override defaults in config/packages/chebur_sphinx.yaml:
chebur_sphinx:
servers:
custom:
host: '%env(SPHINX_HOST)%'
# ...
How can I help you explore Laravel packages today?