有了数据,我们可以测试看看能不能查询到数据。
还是一样的,创建一个命令:
class ElasearchCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:search {query}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$article = Article::search($this->argument('query'))->first();
$this->info($article->title);
}
}

这是我的 titles,我随便输入一个关键字:「清单」,看是否能搜到。

总结
整体完成了:
Elasticsearch 安装; Elasticsearch IK 分词器插件安装; Elasticsearch 可视化工具 ElasticHQ 和 Kibana 的安装和简单使用; Scout 的使用; Elasticsearch 和 Scout 结合使用。接下来就要将更多的内容存入 Elasticsearch 中,为自己的 blog、公众号、自动化搜索等场景提供全文搜索。
参考
推荐一个命令行应用开发工具——Laravel Zero
Artisan 命令行 https://learnku.com/docs/laravel/6.x/artisan/5158
Scout 全文搜索 https://learnku.com/docs/laravel/6.x/scout/5191
How to integrate Elasticsearch in your Laravel App – 2019 edition https://madewithlove.be/how-to-integrate-elasticsearch-in-your-laravel-app-2019-edition/
Kibana Guide https://www.elastic.co/guide/en/kibana/index.html
elasticsearch php-api [https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易采站长站。







