PHP code example of tigusigalpa / yandex-search-php
1. Go to this page and download the library: Download tigusigalpa/yandex-search-php 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/ */
tigusigalpa / yandex-search-php example snippets
igusigalpa\YandexCloudClient\YandexCloudClient;
use Tigusigalpa\YandexSearch\YandexSearchClient;
$cloudClient = new YandexCloudClient('ВАШ_OAUTH_ТОКЕН');
$searchClient = new YandexSearchClient($cloudClient, 'ВАШ_FOLDER_ID');
$results = $searchClient->web()->search('Laravel PHP framework');
echo "Найдено: {$results->found} результатов\n";
foreach ($results->documents as $doc) {
echo "{$doc->title} — {$doc->url}\n";
}
use Tigusigalpa\YandexSearch\Laravel\Facades\YandexSearch;
// Обычный веб-поиск
$results = YandexSearch::web()->search('Laravel');
// Или спросите ИИ
$response = YandexSearch::gen()->search([
['role' => 'ROLE_USER', 'content' => 'Что такое Laravel?']
]);
echo $response->answer;
namespace App\Http\Controllers;
use Tigusigalpa\YandexSearch\YandexSearchClient;
class SearchController extends Controller
{
public function __construct(
private YandexSearchClient $yandexSearch
) {}
public function search(Request $request)
{
$results = $this->yandexSearch->web()->search(
$request->input('query')
);
return view('search.results', compact('results'));
}
}