manticoresoftware / manticoresearch-php
Manticore Search 的 PHP 客户端
3.1.0
2023-09-15 10:43 UTC
Requires (Dev)
- mockery/mockery: *
- phpunit/phpunit: >=7.5
- squizlabs/php_codesniffer: >=3.5
Suggests
- ext-curl: *
- guzzlehttp/psr7: >=1.6
- monolog/monolog: *
- php-http/curl-client: >=1.7
- php-http/httplug: ^1.1
- php-http/message: ^1.7
- dev-master
- 3.1.0.x-dev
- 3.1.0
- 3.0.1.x-dev
- 3.0.1
- 3.0.0.x-dev
- v3.0.0
- 2.3.1.x-dev
- v2.3.1
- v2.3.0
- 2.2.0.x-dev
- v2.2.0
- 2.1.2.x-dev
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.0
- 1.x-dev
- 1.8.0
- 1.7.0
- 1.6.2
- 1.6.0
- 1.5.2
- 1.5.0
- 1.4
- 1.3
- 1.2
- 1.1
- 1.0
- dev-update/nomoreexceptions_msg
- dev-escaping-column-name-when-creating-a-table
- dev-builder
This package is auto-updated.
Last update: 2024-09-04 11:48:14 UTC
README
Manticore Search 的官方 PHP 客户端。
❗ 注意:这是客户端的开发版本。最新版本的说明文档位于 https://github.com/manticoresoftware/manticoresearch-php/tree/3.1.0
特性
- 与 HTTP API 一对一映射
- 具有可插拔选择策略的连接池。默认为静态轮询
- 可插拔 PSR/Log 接口
- 可插拔传输协议。
- 持久连接
要求
需要 PHP 7.1 或更高版本以及本机 JSON 扩展。默认传输处理程序使用 cURL 扩展。
最低 Manticore Search 版本为 2.5.1,并启用了 HTTP 协议。
文档
完整文档可在 docs 文件夹中找到。
Manticore Search 服务器文档:https://manual.manticoresearch.com/。
入门指南
使用 composer 包管理器安装 Manticore Search PHP 客户端
composer require manticoresoftware/manticoresearch-php
初始化索引
require_once __DIR__ . '/vendor/autoload.php'; $config = ['host'=>'127.0.0.1','port'=>9308]; $client = new \Manticoresearch\Client($config); $index = $client->index('movies');
创建索引
$index->create([ 'title'=>['type'=>'text'], 'plot'=>['type'=>'text'], '_year'=>['type'=>'integer'], 'rating'=>['type'=>'float'] ]);
添加文档
$index->addDocument([ 'title' => 'Star Trek: Nemesis', 'plot' => 'The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.', '_year' => 2002, 'rating' => 6.4 ], 1);
一次性添加多个文档
$index->addDocuments([ ['id'=>2,'title'=>'Interstellar','plot'=>'A team of explorers travel through a wormhole in space in an attempt to ensure humanity\'s survival.','_year'=>2014,'rating'=>8.5], ['id'=>3,'title'=>'Inception','plot'=>'A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O.','_year'=>2010,'rating'=>8.8], ['id'=>4,'title'=>'1917 ','plot'=>' As a regiment assembles to wage war deep in enemy territory, two soldiers are assigned to race against time and deliver a message that will stop 1,600 men from walking straight into a deadly trap.','_year'=>2018,'rating'=>8.4], ['id'=>5,'title'=>'Alien','plot'=>' After a space merchant vessel receives an unknown transmission as a distress call, one of the team\'s member is attacked by a mysterious life form and they soon realize that its life cycle has merely begun.','_year'=>1979,'rating'=>8.4] ]);
执行搜索
$results = $index->search('space team')->get(); foreach($results as $doc) { echo 'Document:'.$doc->getId()."\n"; foreach($doc->getData() as $field=>$value) { echo $field.": ".$value."\n"; } }
结果
Document:2
year: 2014
rating: 8.5
title: Interstellar
plot: A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.
带有属性过滤器的文本搜索
$results = $index->search('space team') ->filter('_year','gte',2000) ->filter('rating','gte',8.0) ->sort('_year','desc') ->get(); foreach($results as $doc) { echo 'Document:'.$doc->getId()."\n"; foreach($doc->getData() as $field=>$value) { echo $field.": ".$value."\n"; } }
更新文档
通过文档 ID
$index->updateDocument(['_year'=>2019],4);
通过查询
$index->updateDocument(['_year'=>2019],['match'=>['*'=>'team']]);
获取索引模式
$index->describe();
删除索引
$index->drop();
如果索引不存在,上述操作将失败。为了解决这个问题,请传递一个为 true 的参数,这将使失败变为静默。
$index->drop(true);
许可证
Manticore Search PHP 客户端是开源软件,许可协议为 MIT 许可证