laravel 中文分词插件(elasticsearch)

github 地址:https://github.com/medcl/elasticsearch-analysis-ik

集成包地址:https://github.com/medcl/elasticsearch-rtf

1:下载集成包

2:进入目录->解压

2017-08-03/5983242e9af94.png

3:查看插件列表:

2017-08-03/5983243b97830.png

4:如果内存过小:

拷贝插件:

2017-08-03/5983244f5a4b8.png

删除掉除开analysis-ik的所有插件

2017-08-03/59832454524cc.png

执行删除操作:

2017-08-03/59832462d0b05.png

5:最后

2017-08-03/5983246d4914a.png

7:启动服务

2017-08-03/5983247cca6f6.png

查看是否启动:

2017-08-03/598324907ca4a.png

如果没有启动:执行命令

./bin/elasticsearch  注意  这里执行命令必须要在安装目录下

2017-08-03/598324a08c23a.png

最后 浏览器地址输入:

2017-08-03/598324ae03581.png

安装laravel 使用elastic的包:

安装scout:

地址:http://d.laravel-china.org/docs/5.4/scout

安装 scout 的es 渠道

地址:https://github.com/ErickTamayo/laravel-scout-elastic

在 laravel 中使用命令(增加命令行):

php artisan make:command ESInit

2017-08-03/598324b7e3f02.png

然后修改参数

2017-08-03/598324d62718f.png

2017-08-03/598324e4016a4.png

2017-08-03/598324f13441a.png

执行 php artisan

2017-08-03/598324fb3ae79.png

引入:guzzlehttp/guzzle

2017-08-03/5983254769203.png

在 esinit.php 中

2017-08-03/598325504218f.png

2017-08-03/5983255de5756.png

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $client = new Client();
    // 创建模版
    $url = config('scout.elasticsearch.hosts')[0] . '/_template/tmp';
    $client->put($url, [
        'json' => [
            'template' => config('scout.elasticsearch.index'),
            'settings' => [
                'number_of_shards' => 1
            ],
            'mappings' => [
                '_default_' => [
                    '_all' => [
                        'enabled' => true
                    ],
                    'dynamic_templates' => [
                        [
                            'strings' => [
                                'match_mapping_type' => 'string',
                                'mapping' => [
                                    'type' => 'text',
                                    'analyzer' => 'ik_smart',
                                    'ignore_above' => 256,
                                    'fields' => [
                                        'keyword' => [
                                            'type' => 'keyword'
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]);
    $this->info('=====创建模板成功=====');
    // 创建 index
    $url = config('scout.elasticsearch.hosts')[0] . '/' . config('scout.elasticsearch.index');
    $client->put($url, [
        'json' => [
            'settings' => [
                'refresh_interval' => '5s',
                'number_of_shards' => 1,
                'number_of_replicas' => 0,
            ],
            'mappings' => [
                '_default_' => [
                    '_all' => [
                        'enabled' => false
                    ]
                ]
            ]
        ]
    ]);
    $this->info('=====创建索引成功=====');
}


修改模型

2017-08-03/5983256d01a39.png

重写方法:

2017-08-03/5983257990ea6.png

执行命令:

es:init;


雷亮博客
请先登陆后发表评论
  • 最新评论
  • 总共2条评论
雷亮博客

简简单单:你这个是什么啊

2017-08-05 09:03:43 回复

雷亮博客

心若空丶初夏:哈哈

2017-08-04 10:17:13 回复

  • 本站使用thinkphp搭建 © 2014-2016 www.leigougou.com 版权所有 ICP证:蜀ICP备16024789号-1
  • 联系邮箱:1031041088@qq.com