PHP code example of skylee / ali-open-search-v3
1. Go to this page and download the library: Download skylee/ali-open-search-v3 library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
skylee / ali-open-search-v3 example snippets
$info = config('opensearch');
//开启调试模式
$options = array('debug' => false);
$client = new \OpenSearch\Client\OpenSearchClient($info['app_id'], $info['app_secret'], $info['endPoint'], $options);
// 实例化一个搜索类
$searchClient = new \OpenSearch\Client\SearchClient($client);
// 实例化一个搜索参数类
$params = new \OpenSearch\Util\SearchParamsBuilder();
//设置config子句的hit值
$params->setHits(20);
$params->setAppName('seo');
// 指定搜索关键词
$params->setQuery("default:'{$this->tag}'");
// 指定返回的搜索结果的格式为json.gitignore
$params->setFormat("fulljson");
// 执行搜索,获取搜索结果
$ret = $searchClient->execute($params->build());
$result = json_decode($ret->result,true)['result']['items'];