LaravelPackages.net
Acme Inc.
Toggle sidebar
larva/laravel-scout-sphinxsearch

Laravel Scout Sphinx Driver

37
1
1.0.1
About larva/laravel-scout-sphinxsearch

larva/laravel-scout-sphinxsearch is a Laravel package for laravel scout sphinx driver. It currently has 1 GitHub stars and 37 downloads on Packagist (latest version 1.0.1). Install it with composer require larva/laravel-scout-sphinxsearch. Discover more Laravel packages by larva or browse all Laravel packages to compare alternatives.

Last updated

Laravel Scout Sphinx Driver

Installation

Composer

Use the following command to install package via composer

composer require larva/laravel-scout-sphinxsearch

Configuration

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. Edit this file to set 'sphinxsearch' as a Scout driver:

'driver' => env('SCOUT_DRIVER', 'sphinxsearch'),

And add default Sphinx 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 need.

Usage

  • Add the Laravel\Scout\Searchable trait to the model you would like to make searchable.
  • Customize index name and searchable data for the model:
    public function searchableAs()
    {
        return 'posts_index';
    }
    
    public function toSearchableArray()
    {
        $array = $this->toArray();

        // Customize array...

        return $array;
    }

The 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 index using callback, set the where clause, orderBy or paginate, for example:

$oorders = 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 ones and you need to update/delete records please define public $isRT = true; model's property.

Star History Chart