Last active
May 7, 2019 15:54
-
-
Save teepluss/cdc003544f290899568f4a77c5a47657 to your computer and use it in GitHub Desktop.
Example CloudSearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Aws\CloudSearch\CloudSearchClient; | |
use Aws\CloudSearchDomain\CloudSearchDomainClient; | |
// http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-cloudsearchdomain.html | |
$client = CloudSearchDomainClient::factory(array( | |
//'endpoint' => 'https://doc-example-xxx.ap-southeast-1.cloudsearch.amazonaws.com', | |
'endpoint' => 'https://search-example-xxx.ap-southeast-1.cloudsearch.amazonaws.com', | |
'validation' => false, | |
'version' => 'latest', | |
'credentials' => [ | |
'key' => '[KEY] ', | |
'secret' => '[SECRET]', | |
], | |
'region' => 'ap-southeast-1', | |
)); | |
$batch = [ | |
[ | |
'type' => 'add', | |
'id' => 1, | |
'fields' => ['title' => 'ข้อมูลเพื่อการค้น'] | |
], | |
[ | |
'type' => 'add', | |
'id' => 2, | |
'fields' => ['title' => 'สุดยอดครับ แบบนี้ผมจะทำอะไร'] | |
] | |
]; | |
/* | |
$result = $client->uploadDocuments([ | |
'documents' => json_encode($batch), | |
'contentType' =>'application/json' | |
]); | |
*/ | |
// Use the search operation | |
$result = $client->search(array('query' => 'ผม')); | |
$hitCount = $result->getPath('hits/found'); | |
dump("Hits: {$hitCount}", $result); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have this in version 3?