starkeen/yandex-search-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

starkeen/yandex-search-api

最新稳定版本:1.2.0

Composer 安装命令:

composer require starkeen/yandex-search-api

包简介

Library for using Yandex Search API

README 文档

README

Library for Yandex Search API

Packagist Version (custom server) Packagist PHP Version Support (specify version) GitHub codecov Quality Gate Status Codacy Badge

Description

This library is a convenient way to interact with the Yandex Search API. It allows for easy integration of Yandex search functionality into your PHP projects. The library encapsulates the complex logic of interacting with the API and provides a simple and understandable interface for executing search queries.

Installation

To install the library, add it to your project using Composer:

composer require starkeen/yandex-search-api

Usage

To use the library, you need to get an API key. You can get it on the Yandex Search API page.

<?php

require_once 'vendor/autoload.php';

use YandexSearch\SearchException;
use YandexSearch\SearchRequest;
use YandexSearch\YandexSearchService;

// Create a guzzlehttp client instance
$httpClient = new \GuzzleHttp\Client();

// Create a logger instance (any of LoggerInterface implementations)
$logger = new \Psr\Log\NullLogger();

// Initialize the client with your API key
$client = new YandexSearchService($httpClient, $logger);
$client->setApiId('abcdefg'); // Folder ID from your Yandex Cloud account
$client->setApiKey('A1B2C3D4'); // API key from your Yandex Cloud account

// Your search query
$query = 'Кому на Руси жить хорошо?';
$searchRequest = new SearchRequest($query);

try {
    $response = $client->search($searchRequest);
    // Process the results
    foreach ($response->getResults() as $result) {
        echo 'Title: ' . $result->getTitle() . PHP_EOL;
        echo 'URL: ' . $result->getUrl() . PHP_EOL;
        echo 'Snippet: ' . $result->getSnippet() . PHP_EOL;
    }
} catch (SearchException $e) {
    echo $e->getMessage();
}

Configuration

To use the library, you need to provide your Yandex Search API key and your account ID. You can obtain it by registering your application on the Yandex Cloud Console.

You can set the API key in the code as follows:

$client = new YandexSearchService($httpClient, $logger);
$client->setApiId('abcdefg'); // Folder ID from your Yandex Cloud account
$client->setApiKey('A1B2C3D4'); // API key from your Yandex Cloud account

It is also recommended to store the key in a configuration file and use it when creating an instance of the client.

Questions and Feedback

If you have questions, issues, or suggestions for improvement, please create a new issue in the Issues section on GitHub.

License

This library is distributed under the MIT license. See the LICENSE file for details.

统计信息

  • 总下载量: 821
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固