b3n / php-azure-search
此软件包已被废弃且不再维护。作者建议使用benjaminhirsch/php-azure-search软件包。
一个简单的PHP类,用于与Microsoft Azure Search REST API进行通信
0.9.2
2018-10-27 17:00 UTC
Requires
- php: ^7.0
- ext-json: *
- zendframework/zend-http: ^2.8
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^6.0
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.3
README
PHP的Microsoft Azure Search服务
benjaminhirsch/php-azure-search
是一个简单的PHP工具箱,用于与Microsoft Azure Search服务的REST API交互。
功能
- 创建、更新和删除索引,包括建议器和corsOptions
- 创建、更新和删除所有类型的字段,包括集合
- 列出索引
- 获取索引统计信息
- 添加、更新和删除文档
- 搜索文档
- 获取实时建议
- 计算文档数量
即将推出的功能
- 添加评分配置文件
安装
开始使用最简单的方法是使用composer安装benjaminhirsch/php-azure-search
。
$ composer require benjaminhirsch/php-azure-search
初始化
您可以在Microsoft Azure门户的“搜索服务”下找到您的凭据$azure_url
、$azure_admin_key
和$azure_version
。
$azuresearch = new BenjaminHirsch\Azure\Search\Service(azure_url, azure_admin_key, azure_version);
创建索引
首先,您需要在其中存储文档的索引BenjaminHirsch\Azure\Search\Index
中创建索引。您的索引可以包含尽可能多的字段。添加建议器是可选的,但如果要使用实时搜索(建议),则必须添加。
$index = new BenjaminHirsch\Azure\Search\Index('name of your index'); $index->addField(new BenjaminHirsch\Azure\Search\Index\Field('field name 1', BenjaminHirsch\Azure\Search\Index\Field::TYPE_STRING, true)) ->addField(new BenjaminHirsch\Azure\Search\Index\Field('field name 2', BenjaminHirsch\Azure\Search\Index\Field::TYPE_STRING)) ->addSuggesters(new BenjaminHirsch\Azure\Search\Index\Suggest('livesearch', ['field name(s)'])); $azuresearch->createIndex($index);
删除索引
从Azure中删除整个索引。删除索引也将删除存储在索引中的文档。
$azuresearch->deleteIndex('name of the index to delete');
上传文档
在创建了索引之后,您就可以用数据填充索引了。每个请求的最大数组大小(1000)。
$data['value'][] = [ '@search.action' => BenjaminHirsch\Azure\Search\Index::ACTION_UPLOAD, 'field name 1' => <your value for field name 1>, 'field name 2' => <your value for field name 2> ]; $azuresearch->uploadToIndex('name of your index', $data);
实时搜索(建议)
$azuresearch->suggestions('name of your index', 'your term', 'livesearch')
搜索文档
$azuresearch->search('name of your index', 'your term');