符合中小企业对网站设计、功能常规化式的企业展示型网站建设
本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...
商城网站建设因基本功能的需求不同费用上面也有很大的差别...
手机微信网站开发、微信官网、微信商城网站...
这篇文章给大家分享的是有关Laravel如何使用scout集成elasticsearch做全文搜索的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
为淄博等地区用户提供了全套网页设计制作服务,及淄博网站建设行业解决方案。主营业务为成都网站制作、做网站、淄博网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
仅限于 es6.8版本
laravel 5.5版本
composer require tamayo/laravel-scout-elastic composer require laravel/scout
Using version ^6.1 for laravel/scout ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - tamayo/laravel-scout-elastic 4.0.0 requires laravel/scout ^5.0 -> satisfiable by laravel/scout[5.0.x-dev]. - tamayo/laravel-scout-elastic 4.0.0 requires laravel/scout ^5.0 -> satisfiable by laravel/scout[5.0.x-dev]. - tamayo/laravel-scout-elastic 4.0.0 requires laravel/scout ^5.0 -> satisfiable by laravel/scout[5.0.x-dev]. - Conclusion: don't install laravel/scout 5.0.x-dev - Installation request for tamayo/laravel-scout-elastic ^4.0 -> satisfiable by tamayo/laravel-scout-elastic[4.0.0]. Installation failed, reverting ./composer.json to its original content.
composer require laravel/scout ^5.0
'providers' => [ //es search 加上以下内容 Laravel\Scout\ScoutServiceProvider::class, ScoutEngines\Elasticsearch\ElasticsearchProvider::class, ]
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
'driver' => env('SCOUT_DRIVER', 'elasticsearch'), 'elasticsearch' => [ 'index' => env('ELASTICSEARCH_INDEX', '你的Index名字'), 'hosts' => [ env('ELASTICSEARCH_HOST', ''), ], ],
ELASTICSEARCH_HOST=elastic:密码@你的域名.com:9200
['elastic', 'yourPassword']]); $url = config('scout.elasticsearch.hosts')[0] . '/_template/news'; $params = [ 'json' => [ 'template' => config('scout.elasticsearch.index'), 'settings' => [ 'number_of_shards' => 5 ], 'mappings' => [ '_default_' => [ 'dynamic_templates' => [ [ 'strings' => [ 'match_mapping_type' => 'string', 'mapping' => [ 'type' => 'text', 'analyzer' => 'ik_smart', 'ignore_above' => 256, 'fields' => [ 'keyword' => [ 'type' => 'keyword' ] ] ] ] ] ] ] ] ] ]; $client->put($url, $params); // 创建index $url = config('scout.elasticsearch.hosts')[0] . '/' . config('scout.elasticsearch.index'); $params = [ 'json' => [ 'settings' => [ 'refresh_interval' => '5s', 'number_of_shards' => 5, 'number_of_replicas' => 0 ], 'mappings' => [ '_default_' => [ '_all' => [ 'enabled' => false ] ] ] ] ]; $client->put($url, $params); } }
执行这个命令 生成 mapping
php artisan es:init修改model支持 全文搜索
hasOne(Star::class, 'id', 'star_id'); } public function category() { return $this->hasOne(Category::class, 'id', 'category_id'); } public static function getActivityIdByName($name) { return self::select('id') ->where([ ['status', '=', 1], ['type_id', '=', 2], ['title', 'like', '%' . $name . '%'] ])->get()->pluck('id'); } }导入全文索引信息
php artisan scout:import "App\ActivityNews\Model\ActivityNews"测试简单的全文索引
php artisan tinker >>> App\ActivityNews\Model\ActivityNews::search('略懂皮毛')->get();感谢各位的阅读!关于“Laravel如何使用scout集成elasticsearch做全文搜索”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
网页标题:Laravel如何使用scout集成elasticsearch做全文搜索
新闻来源:http://bjjierui.cn/article/jchsig.html