...
...
'providers'
=> [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::
class
,
Illuminate\Broadcasting\BroadcastServiceProvider::
class
,
Illuminate\Bus\BusServiceProvider::
class
,
Illuminate\Cache\CacheServiceProvider::
class
,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::
class
,
Illuminate\Cookie\CookieServiceProvider::
class
,
Illuminate\Database\DatabaseServiceProvider::
class
,
Illuminate\Encryption\EncryptionServiceProvider::
class
,
Illuminate\Filesystem\FilesystemServiceProvider::
class
,
Illuminate\Foundation\Providers\FoundationServiceProvider::
class
,
Illuminate\Hashing\HashServiceProvider::
class
,
Illuminate\Mail\MailServiceProvider::
class
,
Illuminate\Notifications\NotificationServiceProvider::
class
,
Illuminate\Pagination\PaginationServiceProvider::
class
,
Illuminate\Pipeline\PipelineServiceProvider::
class
,
Illuminate\Queue\QueueServiceProvider::
class
,
Illuminate\Redis\RedisServiceProvider::
class
,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::
class
,
Illuminate\Session\SessionServiceProvider::
class
,
Illuminate\Translation\TranslationServiceProvider::
class
,
Illuminate\Validation\ValidationServiceProvider::
class
,
Illuminate\View\ViewServiceProvider::
class
,
/*
* Package Service Providers...
*/
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::
class
,
App\Providers\AuthServiceProvider::
class
,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::
class
,
App\Providers\RouteServiceProvider::
class
,
Laravel\Scout\ScoutServiceProvider::
class
,
],
...
...
$ php artisan vendor:publish --provider=
"Laravel\Scout\ScoutServiceProvider"
Copied File [
/vendor/laravel/scout/config/scout
.php] To [
/config/scout
.php]
Publishing complete.
<?php
return
[
/*
|--------------------------------------------------------------------------
| Default Search Engine
|--------------------------------------------------------------------------
|
| This option controls the default search connection that gets used while
| using Laravel Scout. This connection is used when syncing all models
| to the search service. You should adjust this based on your needs.
|
| Supported: "algolia", "null"
|
*/
'driver'
=> env(
'SCOUT_DRIVER'
,
'algolia'
),
/*
|--------------------------------------------------------------------------
| Index Prefix
|--------------------------------------------------------------------------
|
| Here you may specify a prefix that will be applied to all search index
| names used by Scout. This prefix may be useful if you have multiple
| "tenants" or applications sharing the same search infrastructure.
|
*/
'prefix'
=> env(
'SCOUT_PREFIX'
,
''
),
/*
|--------------------------------------------------------------------------
| Queue Data Syncing
|--------------------------------------------------------------------------
|
| This option allows you to control if the operations that sync your data
| with your search engines are queued. When this is set to "true" then
| all automatic data syncing will get queued for better performance.
|
*/
'queue'
=> env(
'SCOUT_QUEUE'
, false),
/*
|--------------------------------------------------------------------------
| Database Transactions
|--------------------------------------------------------------------------
|
| This configuration option determines if your data will only be synced
| with your search indexes after every open database transaction has
| been committed, thus preventing any discarded data from syncing.
|
*/
'after_commit'
=> false,
/*
|--------------------------------------------------------------------------
| Chunk Sizes
|--------------------------------------------------------------------------
|
| These options allow you to control the maximum chunk size when you are
| mass importing data into the search engine. This allows you to fine
| tune each of these chunk sizes based on the power of the servers.
|
*/
'chunk'
=> [
'searchable'
=> 500,
'unsearchable'
=> 500,
],
/*
|--------------------------------------------------------------------------
| Soft Deletes
|--------------------------------------------------------------------------
|
| This option allows you to control whether to keep soft deleted records in
| the search indexes. Maintaining soft deleted records can be useful
| if your application still needs to search for the records later.
|
*/
'soft_delete'
=> false,
/*
|--------------------------------------------------------------------------
| Identify User
|--------------------------------------------------------------------------
|
| This option allows you to control whether to notify the search engine
| of the user performing the search. This is sometimes useful if the
| engine supports any analytics based on this application's users.
|
| Supported engines: "algolia"
|
*/
'identify'
=> env(
'SCOUT_IDENTIFY'
, false),
/*
|--------------------------------------------------------------------------
| Algolia Configuration
|--------------------------------------------------------------------------
|
| Here you may configure your Algolia settings. Algolia is a cloud hosted
| search engine which works great with Scout out of the box. Just plug
| in your application ID and admin API key to get started searching.
|
*/
'algolia'
=> [
'id'
=> env(
'ALGOLIA_APP_ID'
,
'XXXXXX'
),
'secret'
=> env(
'ALGOLIA_SECRET'
,
'XXXXXXXXXXXXXXXXXXXXXXXX'
),
],
];
...
...
ALGOLIA_APP_ID=XXXXXX
ALGOLIA_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXX
...
...
$composer require algolia
/algoliasearch-client-php
<?php
namespace
App;
use
Illuminate\Database\Eloquent\Model;
use
Laravel\Scout\Searchable;
class
Post
extends
Model
{
use
Searchable;
...
...
}
/**
* Get the indexable data array for the model.
*
* @return array
*/
public
function
toSearchableArray()
{
$array
=
$this
->toArray();
return
array
(
'id'
=>
$array
[
'id'
],
'name'
=>
$array
[
'name'
]);
}
$php artisan scout:
import
"App\Post"
这应该一次导入 Post 模型的所有记录!它们一被导入就会被索引,所以我们已经准备好查询记录了。继续探索 Algolia 仪表板以查看导入的记录和其他实用程序。
相关标签: