search
Homephp教程php手册ElasticSearch全文搜索引擎

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

下载文件解压到
ThinkPHP\Library\Vendor\<?php <br /> namespace Home\Controller;<br> <br> use Think\Controller;<br> <br> class EcController extends Controller<br> {<br> <br>     public function _initialize()<br>     {<br>         Vendor('Elasticsearch.autoload');<br>         $params['hosts'] = array(<br>             '127.0.0.1:9200'<br>         );<br>         $this->client = new \Elasticsearch\Client($params);<br>     }<br> <br>     public function 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>     public function add_document()<br>     {<br>         $params = array();<br>         $params['body'] = array(<br>             'testField' => '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>     public function delete_index()<br>     {<br>         $deleteParams['index'] = 'my_index';<br>         $this->client->indices()->delete($deleteParams);<br>     }<br> <br>     public function 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>     public function 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>     public function search()<br>     {<br>         $searchParams['index'] = 'my_index';<br>         $searchParams['type'] = 'my_index';<br>         $searchParams['from'] = 0;<br>         $searchParams['size'] = 100;<br>         $searchParams['sort'] = array(<br>             '_score' => array(<br>                 'order' => 'desc'<br>             )<br>         );<br>         // $searchParams['body']['query']['match']['testField'] = 'abc';<br>         $retDoc = $this->client->search($searchParams);<br>         print_r($retDoc);<br>     }<br> <br>     public function 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.zip ( 1.53 MB 下载:266 次 )

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

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software