2017 © Pedro Peláez
 

library opensearch

opensearch-sdk-php

image

mofing/opensearch

opensearch-sdk-php

  • Saturday, June 23, 2018
  • by wcj343169893
  • Repository
  • 1 Watchers
  • 0 Stars
  • 37 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

openSearch php for aliyun

基于官方opensearch-sdk-PHP 改版, (*1)

安装

``` bash $ composer install "mofing/opensearch":"~1.0", (*2)

或者修改composer.json

{ "require": { "mofing/opensearch": "~1.0" } }, (*3)


## 用法 ###1.获取key和secret 在 <https://ak-console.aliyun.com/#/accesskey> 下的Access Key管理,可以适用阿里云的很多sdk,所以建议写成静态变量 ```php $accessKey = "LTAICZ5bcHEHwg3d";//Access Key ID $secret = "kFLCYaxTFedSNh9rJcjM3KHBkDoxlc";//Access Key Secret

2.配置搜索参数

$host = "http://opensearch-cn-hangzhou.aliyuncs.com";//公网API域名或者内网API域名
$options = [
    'debug' => true
];
//初始化授权
$openSearchClient = new OpenSearchClient($accessKey, $secret, $host, $options);
//初始化搜索客户端
$searchClient = new SearchClient($openSearchClient);
//设置搜索参数
$params = new SearchParamsBuilder();
//设置config子句的start值
$params->setStart(0);
//设置config子句的hit值
$params->setHits(20);
// 指定一个应用用于搜索
$params->setAppName('mofing_shops');
// 指定搜索关键词
$params->setQuery("title:'深圳'");
// 指定返回的搜索结果的格式为json
$params->setFormat("json");
//添加排序字段
//$params->addSort('id', SearchParamsBuilder::SORT_DECREASE);
// 执行搜索,获取搜索结果
$ret = $searchClient->execute($params->build());
// 将json类型字符串解码
$result = $ret->getItems();
//$result = json_decode($ret->result);
print_r($result);

--返回值, (*4)

Array
(
    [0] => stdClass Object
        (
            [id] => 3217306
            [title] => 深圳
            [index_name] => name
        )

    [1] => stdClass Object
        (
            [id] => 2689102
            [title] => 深圳 i 摄摄影培训
            [index_name] => name
        )
)

The Versions

23/06 2018

dev-master

9999999-dev

opensearch-sdk-php

  Sources   Download

The Requires

 

The Development Requires

sdk aliyun opensearch

23/06 2018

1.0.1

1.0.1.0

opensearch-sdk-php

  Sources   Download

The Requires

 

The Development Requires

sdk aliyun opensearch

21/06 2018

1.0.0

1.0.0.0

opensearch-sdk-php

  Sources   Download

The Requires

 

The Development Requires

sdk aliyun opensearch