首页 > php教程 > php手册 > ElasticSearch全文搜索引擎

ElasticSearch全文搜索引擎

WBOY
发布: 2016-06-07 11:38:16
原创
2235 人浏览过

ElasticSearch全文搜索引擎 ,是一款很好的搜索框架!用来做网站的搜索,可以对数据库压力起到一定的缓解作用!
之前给大家带来的是用curl来实现的大家有兴趣可以看看
http://www.thinkphp.cn/topic/29297.html
今天这里给大家带来的是官网提供的 PHP API
整合thinkphp3.2

下载文件解压到
ThinkPHPLibraryVendor<?php <br /> 命名空间 HomeController;<br> <br> 使用 ThinkController;<br> <br> EcController 类扩展了 Controller<br> {<br> <br>     公共函数_initialize()<br>     {<br>         Vendor('Elasticsearch.autoload');<br>         $params['hosts'] = 数组(<br>             '127.0.0.1:9200'<br>         );<br>         $this->client = new ElasticsearchClient($params);<br>     }<br> <br>     公共函数create_index()<br>     {<br>         $indexParams['index'] = 'my_index';<br>         $indexParams['type'] = 'my_index';<br>         $indexParams['body']['settings']['number_of_shards'] = 2;<br>         $indexParams['body']['settings']['number_of_replicas'] = 0;<br>         $this->client->create($indexParams);<br>     }<br> <br>     公共函数 add_document()<br>     {<br>         $params = array();<br>         $params['body'] = 数组(<br>             '测试字段' => 'dfdsfdsf'<br>         );<br>         $params['index'] = 'my_index';<br>         $params['type'] = 'my_index';<br>         $params['id'] = 'w1231313';<br>         $ret = $this->client->index($params);<br>     }<br> <br>     公共函数delete_index()<br>     {<br>         $deleteParams['index'] = 'my_index';<br>         $this->client->indices()->delete($deleteParams);<br>     }<br> <br>     公共函数delete_document()<br>     {<br>         $deleteParams = array();<br>         $deleteParams['index'] = 'my_index';<br>         $deleteParams['type'] = 'my_index';<br>         $deleteParams['id'] = 'AU4Kmmj-WOmOrmyOj2qf';<br>         $retDelete = $this->client->delete($deleteParams);<br>     }<br>     公共函数 update_document()<br>     {<br>         $updateParams = array();<br>         $updateParams['index'] = 'my_index';<br>         $updateParams['type'] = 'my_index';<br>         $updateParams['id'] = 'my_id';<br>         $updateParams['body']['doc']['asas']  = '111111';<br>        $response = $this->client->update($updateParams);<br>          <br>     }<br>     公共函数 search()<br>     {<br>         $searchParams['index'] = 'my_index';<br>        $searchParams['type'] = 'my_index';<br>         $searchParams['from'] = 0;<br>         $searchParams['size'] = 100;<br>         $searchParams['sort'] = 数组(<br>             '_score' =>; 数组(<br>                 '订单' => '描述'<br>             )<br>         );<br>         // $searchParams['body']['query']['match']['testField'] = 'abc';<br>         $retDoc = $this->client->search($searchParams);<br>         print_r($retDoc);<br>     }<br> <br>     公共函数 get_document()<br>     {<br>         $getParams = array();<br>         $getParams['index'] = 'my_index';<br>         $getParams['type'] = 'my_index';<br>         $getParams['id'] = 'AU4Kn-knWOmOrmyOj2qg';<br>         $retDoc = $this->client->get($getParams);<br>         print_r($retDoc);<br>     }<br> }<br> ?>

ElasticSearch全文搜索引擎 Elasticsearch.zip ( 1.53 MB 下载:266次 )

AD:真正免费,域名虚机企业邮箱=0元

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板