PHP code example of tarre / laravel-redis-scout-engine
1. Go to this page and download the library: Download tarre/laravel-redis-scout-engine library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tarre / laravel-redis-scout-engine example snippets
return [
// ....
/*
|--------------------------------------------------------------------------
| Redis configuration
|--------------------------------------------------------------------------
|
*/
'redis' => [
/*
|--------------------------------------------------------------------------
| What connection to use
|--------------------------------------------------------------------------
|
| Decide which redis connection will be used by the Engine
|
| Read more here: https://laravel.com/docs/10.x/redis
|
*/
'connection' => [
'name' => null, // use default connection
],
/*
|--------------------------------------------------------------------------
| Chunk size for redis hScan
|--------------------------------------------------------------------------
|
|
| Read more here: https://redis.io/commands/hscan
|
*/
'scan_chunk' => 1000,
/*
|--------------------------------------------------------------------------
| Search method
|--------------------------------------------------------------------------
|
| Decide which search method to use when searching
|
| * STRPOS (case-sensitive https://php.net/strpos)
| * STRIPOS (DEFAULT) (case-insensitive https://php.net/stripos)
| * WILDCARD (case-insensitive preg_match but it will only accept "*" as wildcard)
| * REGEX (Can cause exceptions https://php.net/preg_match)
*/
'method' => \Tarre\RedisScoutEngine\SearchMethods::STRIPOS,
/*
|--------------------------------------------------------------------------
| orderBy sort options
|--------------------------------------------------------------------------
|
| Read more about sort options on PHPs official docs
|
| https://www.php.net/manual/en/function.sort.php
*/
'sort_options' => SORT_NATURAL
]
];
use App\Models\User;
use Tarre\RedisScoutEngine\Callback;
User::search('xxxx', fn(Callback $cb) => $cb->mapResult(fn(User $user) => ['id' => $user->id, 'name' => $user->name, 'abc' => 123]))->paginate()
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.