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

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)
    }
  }
}


分享到:

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

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

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

分享给朋友:

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

php获取从百度搜索进入网站的关键词

<?php    function search_word_from() {     $referer = isset($_SERVER['HTTP_REFERER'])?...

图文解说Navicat使用ssh方式连接远程MySql服务器

图文解说Navicat使用ssh方式连接远程MySql服务器

如何使用Navicat 8.0 for MySQL连接公司服务器的数据库,但我也是第一次接触这个软件,搞了半天也没连上,在网上找了很多解决的办法,其中就有使用ssh方式连接的,但写的不够详细,因此还是费了一番功夫,自己搞定的,不敢独享,特记录下来 与大家分享。首先,在Navicat的连接设置里选择S...

wamp下虚拟主机的配置

1  编辑httpd.conf,查找Include conf/extra/httpd-vhosts.conf,把前面注释符号“#”删掉。 2  编辑httpd-vhosts.conf,我把WAMPServer安装在D:/wamp,所以我这里的路径是D:\wamp\Apache2\...

推荐一些国内的Jquery CDN免费服务

Jquery是个非常流行的JS前端框架,在很多网站都能看到它的身影。很多网站都喜欢采用一些Jquery CDN加速服务,这样网站加载jquery会更快。之前火端网络的一些网站都是使用Google的jquery CDN,如:http://ajax.googleapis.com/ajax/lib...

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

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

php利用百度地图API进行IP定位和GPS定位

最 近在做一个手机端的webapp地图应用,而核心内容当然是定位了,但是定位的话有几种方式,IP定位,GPS定位,基站定位(这个貌似webapp用不 了), 那么剩下核心的gps定位和ip定位了,我们知道,html5有定位API,但是该API拿到的GPS数据是硬件坐标,无法直接显示在地图上。...

发表评论

访客

看不清,换一张

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