7 changed files with 747 additions and 79 deletions
-
45app/Console/Commands/EsTest.php
-
48app/Models/LanzuGoods.php
-
2composer.json
-
601composer.lock
-
1config/app.php
-
23config/elasticsearch.php
-
106config/scout.php
@ -0,0 +1,45 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use App\Models\LanzuGoods; |
|||
|
|||
class EsTest extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'command:EsTest'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'Command 测试Es搜索'; |
|||
|
|||
/** |
|||
* Create a new command instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
/** |
|||
* Execute the console command. |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
$gds = LanzuGoods::search('火龙果')->get(); |
|||
dd($gds); |
|||
return 0; |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Laravel\Scout\Searchable; |
|||
|
|||
class LanzuGoods extends Model |
|||
{ |
|||
use Searchable; |
|||
|
|||
protected $table = 'lanzu_goods'; |
|||
protected $dateFormat = 'U'; |
|||
|
|||
|
|||
public function searchableAs() |
|||
{ |
|||
return 'lanzu-goods-test'; |
|||
} |
|||
|
|||
public function toSearchableArray() |
|||
{ |
|||
return [ |
|||
'name' => $this->name, |
|||
'market_id' => $this->market_id, |
|||
'store_id' => $this->store_id, |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* 指定 搜索索引中存储的唯一ID |
|||
* @return mixed |
|||
*/ |
|||
public function getScoutKey() |
|||
{ |
|||
return $this->id; |
|||
} |
|||
|
|||
/** |
|||
* 指定 搜索索引中存储的唯一ID的键名 |
|||
* @return string |
|||
*/ |
|||
public function getScoutKeyName() |
|||
{ |
|||
return 'id'; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<?php |
|||
|
|||
return [ |
|||
'indices' => [ |
|||
'mappings' => [ |
|||
'lanzu-goods-test' => [ |
|||
"properties"=> [ |
|||
"name"=> [ |
|||
"type"=> "text", |
|||
"analyzer"=> "ik_max_word", |
|||
"search_analyzer"=> "ik_smart" |
|||
], |
|||
'store_id'=>[ |
|||
"type"=> "integer", |
|||
], |
|||
'market_id'=>[ |
|||
"type"=> "integer", |
|||
] |
|||
] |
|||
] |
|||
] |
|||
], |
|||
]; |
|||
@ -0,0 +1,106 @@ |
|||
<?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', 'Matchish\ScoutElasticSearch\Engines\ElasticSearchEngine'), |
|||
|
|||
/* |
|||
|-------------------------------------------------------------------------- |
|||
| 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), |
|||
|
|||
/* |
|||
|-------------------------------------------------------------------------- |
|||
| 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 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', ''), |
|||
'secret' => env('ALGOLIA_SECRET', ''), |
|||
], |
|||
|
|||
]; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue