eljump/laravel-scout-sphinx
最新稳定版本:v1.0.0
Composer 安装命令:
composer require eljump/laravel-scout-sphinx
包简介
Laravel Scout Sphinx Driver
README 文档
README
Introduction
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.
Installation
Composer
Use the following command to install this package via Composer.
composer require constantable/laravel-scout-sphinx
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, 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.
Usage
- Add the
Laravel\Scout\Searchabletrait to the model you would like to make searchable. - Customize the index name and searchable data for the model:
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.
Credits
License
Licensed under the MIT license
统计信息
- 总下载量: 444
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-28