OSS AISearch lets you search objects in a bucket by semantic content, OSS metadata, multimedia metadata, ETags, object tags, and custom metadata. This topic shows how to use AISearch with the OSS SDK for PHP V2.
Prerequisites
Before you begin, ensure that you have:
PHP and Composer installed, with the OSS SDK for PHP V2 dependency added (
alibabacloud/oss-v2)OSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETset as environment variablesAn OSS bucket in a supported region
The examples in this topic use the China (Hangzhou) region (cn-hangzhou) and a public endpoint. To access OSS from other Alibaba Cloud services within the same region, use an internal endpoint. For more information, see OSS regions and endpoints.Setup
All examples in this topic share the same client initialization. Run this setup once before calling any AISearch operation.
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use AlibabaCloud\Oss\V2 as Oss;
// Read credentials from environment variables.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();
$cfg = Oss\Config::loadDefault();
$cfg->setCredentialsProvider($credentialsProvider);
$cfg->setRegion('<region>'); // e.g., cn-hangzhou
// $cfg->setEndpoint('<endpoint>'); // Uncomment to use a custom endpoint.
$client = new Oss\Client($cfg);Replace <region> with the region where your bucket is located.
For more examples of how to configure credentials, see Configure access credentials. For more client configuration options, see Configure a client.
Get metadata index status
// Retrieve the current status of the metadata index for the bucket.
$request = new Oss\Models\GetMetaQueryStatusRequest(
bucket: $bucket
);
$result = $client->getMetaQueryStatus($request);
echo 'status code: ' . $result->statusCode . PHP_EOL;
echo 'request ID: ' . $result->requestId . PHP_EOL;
echo 'meta query status: ' . var_export($result->metaQueryStatus, true) . PHP_EOL;Disable AISearch
// Disable AISearch on the specified bucket.
$request = new \AlibabaCloud\Oss\V2\Models\CloseMetaQueryRequest(
bucket: $bucket
);
$result = $client->closeMetaQuery($request);
echo 'status code: ' . $result->statusCode . PHP_EOL;
echo 'request ID: ' . $result->requestId . PHP_EOL;What's next
For a complete runnable sample, see the GitHub example.
For AISearch concepts and use cases, see AISearch.
For the underlying API operations, see Data indexing.