码迷,mamicode.com
首页 > Web开发 > 详细

ElasticSearch全文搜索引擎整合thinkphp

时间:2016-12-15 01:03:09      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:idt   cti   解压   ams   搜索   extension   let   int   middle   

下载文件解压到
ThinkPHP\Library\Vendor\

  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class EcController extends Controller
  5. {
  6.     public function _initialize()
  7.     {
  8.         Vendor(‘Elasticsearch.autoload‘);
  9.         $params[‘hosts‘] = array(
  10.             ‘127.0.0.1:9200‘
  11.         );
  12.         $this->client = new \Elasticsearch\Client($params);
  13.     }
  14.     public function create_index()
  15.     {
  16.         $indexParams[‘index‘] = ‘my_index‘;
  17.         $indexParams[‘type‘] = ‘my_index‘;
  18.         $indexParams[‘body‘][‘settings‘][‘number_of_shards‘] = 2;
  19.         $indexParams[‘body‘][‘settings‘][‘number_of_replicas‘] = 0;
  20.         $this->client->create($indexParams);
  21.     }
  22.     public function add_document()
  23.     {
  24.         $params = array();
  25.         $params[‘body‘] = array(
  26.             ‘testField‘ => ‘dfdsfdsf‘
  27.         );
  28.         $params[‘index‘] = ‘my_index‘;
  29.         $params[‘type‘] = ‘my_index‘;
  30.         $params[‘id‘] = ‘w1231313‘;
  31.         $ret = $this->client->index($params);
  32.     }
  33.     public function delete_index()
  34.     {
  35.         $deleteParams[‘index‘] = ‘my_index‘;
  36.         $this->client->indices()->delete($deleteParams);
  37.     }
  38.     public function delete_document()
  39.     {
  40.         $deleteParams = array();
  41.         $deleteParams[‘index‘] = ‘my_index‘;
  42.         $deleteParams[‘type‘] = ‘my_index‘;
  43.         $deleteParams[‘id‘] = ‘AU4Kmmj-WOmOrmyOj2qf‘;
  44.         $retDelete = $this->client->delete($deleteParams);
  45.     }
  46.     public function update_document()
  47.     {
  48.         $updateParams = array();
  49.         $updateParams[‘index‘] = ‘my_index‘;
  50.         $updateParams[‘type‘] = ‘my_index‘;
  51.         $updateParams[‘id‘] = ‘my_id‘;
  52.         $updateParams[‘body‘][‘doc‘][‘asas‘]  = ‘111111‘;
  53.        $response = $this->client->update($updateParams);
  54.          
  55.     }
  56.     public function search()
  57.     {
  58.         $searchParams[‘index‘] = ‘my_index‘;
  59.         $searchParams[‘type‘] = ‘my_index‘;
  60.         $searchParams[‘from‘] = 0;
  61.         $searchParams[‘size‘] = 100;
  62.         $searchParams[‘sort‘] = array(
  63.             ‘_score‘ => array(
  64.                 ‘order‘ => ‘desc‘
  65.             )
  66.         );
  67.         // $searchParams[‘body‘][‘query‘][‘match‘][‘testField‘] = ‘abc‘;
  68.         $retDoc = $this->client->search($searchParams);
  69.         print_r($retDoc);
  70.     }
  71.     public function get_document()
  72.     {
  73.         $getParams = array();
  74.         $getParams[‘index‘] = ‘my_index‘;
  75.         $getParams[‘type‘] = ‘my_index‘;
  76.         $getParams[‘id‘] = ‘AU4Kn-knWOmOrmyOj2qg‘;
  77.         $retDoc = $this->client->get($getParams);
  78.         print_r($retDoc);
  79.     }
  80. }
  81. ?>

技术分享 Elasticsearch.zip

ElasticSearch全文搜索引擎整合thinkphp

标签:idt   cti   解压   ams   搜索   extension   let   int   middle   

原文地址:http://www.cnblogs.com/qijiu/p/6181558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!