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

PHP使用elasticSearch进行分词

admin8年前 (2018-06-13)技术文档1662
  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)
    }
  }
}


分享到:

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

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

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

分享给朋友:

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

appcan 云打包的方法

appcan 云打包的方法...

php 获取页面内容

function get_contents($url){     if(function_exists('file_get_contents')){       &nbs...

dz第三方模块添加方法

dz第三方模块添加方法

使用dz做网站的朋友有时候会用到第三方模块专题,这就会遇到一个模块通信的问题,可是弄了半天就是“数据无法识别,请返回”, 也够雷人的,ok,这你就给大家分享下本人的一点经验,以供大家参考!dz第三方模块添加方法...

PHP实现登陆后台限制到只允许一台机器在线

方法一:# <?php# ob_start();# session_start();# class CC{#   private $REFURL="http://www.php100.com";    //登陆成功后转换页面#   private $LoginFLAG=fa...

wamp虚拟主机配置

1、首先打开apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#,启用虚拟主机功能2、先把localhost配置好,免得以后访问localhost出现问题,我的wamp项目根目录是D:\wamp\www。将下面信息添加到...

如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)

如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)?先上代码进行java时间转换成unix timestampimport java.text.DateFormat;   import java.text.ParseExceptio...

发表评论

访客

看不清,换一张

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