当前位置:首页 > 技术文档 > 正文内容

PHP使用elasticSearch进行分词

admin8年前 (2018-06-13)技术文档1665
  1. 安装最行版本ElasticSearch,推荐使用rpm -ivh安装,下载地址:https://github.com/elastic/elasticsearch/releases

  2. 下载  /elasticsearch-analysis-ik

  3. 安装方式两种:在线安装、离线安装

    (1)在线安装:

  4. cd /usr/share/elasticsearch/
    ./bin/elastic-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.4/elasticsearch-analysis-ik-6.2.4.zip

       离线安装:需要用到maven,

        下载ik源码到磁盘,进入目录,

    mvn package,

        然后会下载依赖包,生成一个target文件夹,

        进入target/releases文件夹,把打包好的文件移动到plugins文件夹,并unzip解压,

        重启elasticsearch服务,

systemctrl status  elasticsearch.service

        确认下服务是否成功启动,如有故障进行  排查(点击看看常见错误),

    4.PHP安装composer

    5.composer安装

    composer reuqire "elasticsearch/elasticsearch"
 
 6.PHP代码调用:
     $client=ClientBuilder::create()->setHosts(['192.168.32.128'])->build();
        $params['index'] = 'index';
        $params['body'] = [
//            'analyzer' => 'ik_max_word',
            'analyzer' => 'ik_smart',
//            'text' => '英雄联盟最强王者'
//            'text' => '中华人民共和国国歌'
            'text' => 'based index manager for Elasticsearch'
        ];
       $res=$client ->indices()->analyze($params);

        打印结果如下:

        

array(1) {
  ["tokens"] => array(4) {
    [0] => array(5) {
      ["token"] => string(5) "based"
      ["start_offset"] => int(0)
      ["end_offset"] => int(5)
      ["type"] => string(7) "ENGLISH"
      ["position"] => int(0)
    }
    [1] => array(5) {
      ["token"] => string(5) "index"
      ["start_offset"] => int(6)
      ["end_offset"] => int(11)
      ["type"] => string(7) "ENGLISH"
      ["position"] => int(1)
    }
    [2] => array(5) {
      ["token"] => string(7) "manager"
      ["start_offset"] => int(12)
      ["end_offset"] => int(19)
      ["type"] => string(7) "ENGLISH"
      ["position"] => int(2)
    }
    [3] => array(5) {
      ["token"] => string(13) "elasticsearch"
      ["start_offset"] => int(24)
      ["end_offset"] => int(37)
      ["type"] => string(7) "ENGLISH"
      ["position"] => int(3)
    }
  }
}


分享到:

扫描二维码推送至手机访问。

版权声明:本文由云河空间发布,如需转载请注明出处。

本文链接:https://yuyunhe.cn/index.php/post/265.html

分享给朋友:

“PHP使用elasticSearch进行分词” 的相关文章

php检查用户名是否符合规定

<?php   /**  * 检查用户名是否符合规定 (两个字符以上,只能有中文,字母,数字,下划线的)  *  * @param STRING $username 要检查的用户名...

php二维数组转换为一维数组的几种方法

在开发过程中,我们经常需要将二维数组转为一维数组,个人总结了2种方法,分享给大家如何将下面的二维数组转为一维数组。复制代码 代码如下:$msg = array(  array(    'id'=>'45',    'name'=>'...

PHP开发之THINKPHP多表联合查询操作的三种方法

THINKPHP 中关联查询(多表查询)可以使用 table() 方法或和join方法,请看示例: 联合查询         1、原生查询    &...

php取整函数ceil,floor,round,intval函数的区别

开发过程中,遇到数据处理取整的时候,你会用哪个呢,小涛来介绍一下:PHP取整函数有ceil,floor,round,intval,下面详细介绍一下:1、ceil — 进一法取整说明float ceil ( float $value )返回不小于 ...     ...

阿里云上配置CentOS安装Git(小沐git安装命令全集整理版)

阿里云上配置CentOS安装Git(小沐git安装命令全集整理版)

yum install curl yum install curl-devel yum install zlib-devel yum install openssl-devel yum i...

PHP公历农历转换(阴历阳历转换)阴历和阳历转换

<?php class Lunar {     private  $_SMDay = array(1 => 31, 28, 31, 30,...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。