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

PHP使用elasticSearch进行分词

admin8年前 (2018-06-13)技术文档1663
  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   /**  * 检查用户名是否符合规定 (两个字符以上,只能有中文,字母,数字,下划线的)  *  * @param STRING $username 要检查的用户名...

抓取最近八天天气(非利用接口,直接从网站提取)

<?php    /*     *特别注意,第一天没有最高气温数据,第八天没有最低气温数据     *注意对数字进行过滤时不要忘记对负号进行判断   &nb...

php批量下载图片

假如现在我现在发现一个网站上的图片保存方式是1001 – 1999目录下都存放着从1开始(数量不等)的.jpg图片,现在我决定用php的方法将图片按照自己需要的样式直接下载到本地   假如图片开始地址为:http://image.xxx.com/img/1001/1...

jQuery编程的最佳实践

加载jQuery1.坚持使用CDN来加载jQuery,这种别人服务器免费帮你托管文件的便宜干嘛不占呢。点击查看使用CDN的好处,点此查看一些主流的jQuery CDN地址。<script type="text/javascript" src="...

浅谈 PHP 与手机 APP 开发(API 接口开发)

文章转载自:http://www.thinkphp.cn/topic/5023.html这个帖子写给不太了解PHP与API开发的人一、先简单回答两个问题:1、PHP 可以开发客户端?答:不可以,因为PHP是脚本语言,是负责完成 B/S架构 或 C/S架构 的S部分,即:服务端的开发。(别去纠结 GT...

TP 查询缓存

<?php     function cache_data($sql){             $SqlDao&nbs...

发表评论

访客

看不清,换一张

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