constantable/laravel-scout-sphinx is a Laravel package for laravel scout sphinx driver.
It currently has 20 GitHub stars and 55.514 downloads on Packagist (latest version 3.0).
Install it with composer require constantable/laravel-scout-sphinx.
Discover more Laravel packages by constantable
or browse all Laravel packages to compare alternatives.
Last updated
This package is fork of constantable/laravel-scout-sphinx. package offers advanced functionality for searching and filtering data using the Sphinx full text search server for Laravel Scout.
Use the following command to install this package via Composer.
composer require constantable/laravel-scout-sphinx
Publish the Scout configuration using the vendor:publish Artisan command.
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
This command will publish the scout.php configuration file to your config directory, which you can than edit and set sphinxsearch as the Scout driver.
'driver' => env('SCOUT_DRIVER', 'sphinxsearch'),
To configure the connection to Sphinx server add the following (i.e. default) connection options.
'sphinxsearch' => [
'host' => env('SPHINX_HOST', 'localhost'),
'port' => env('SPHINX_PORT', '9306'),
'socket' => env('SPHINX_SOCKET'),
'charset' => env('SPHINX_CHARSET'),
],
Override these variables in your .env file if required.
Laravel\Scout\Searchable trait to the model you would like to make searchable.
public function searchableAs()
{
return 'posts_index';
}
public function toSearchableArray()
{
$array = $this->toArray();
// Customize array...
return $array;
}
A basic search:
$orders = App\Order::search('Star Trek')->get();
Please refer to the Scout documentation for additional information. You can run more complex queries on the index by using a callback, setting the where clause, orderBy, or paginate threshold. For example:
$orders = App\Order::search($keyword, function (SphinxQL $query) {
return $query->groupBy('description');
})
->where('status', 1)
->orderBy('date', 'DESC')
->paginate(20);
Note: Changes on Sphinx indexes are only allowed for RT (Real-time) indexes. If you have these and need to update/delete records please define public $isRT = true; in the model's property.
Licensed under the MIT license