openeuropa/europa-search-client

用于与 Europa Search 服务通信的 PHP 客户端库。

1.0.0-alpha8 2024-09-02 10:38 UTC

README

Build Status Packagist

描述

Europa Search Client 是一个提供 PHP API 以消费 Europa Search 服务的库。

安装

使用 Composer 安装此包

$ composer require openeuropa/europa-search-client

使用方法

所有调用都应该通过实例化客户端类来完成

require_once 'vendor/autoload.php';

$client = new \OpenEuropa\EuropaSearchClient\Client(
    new \GuzzleHttp\Client(),
    new \Http\Factory\Guzzle\RequestFactory(),
    new \Http\Factory\Guzzle\StreamFactory(),
    new \Http\Factory\Guzzle\UriFactory(),
    [
        // For a full list of options see "Configuration".
        'apiKey' => 'foo',
        'searchApiEndpoint' => 'https://example.com/search',
    ]
);

在上面的例子中,我们传递了 Guzzle HTTP 客户端、请求、流和 URI 工厂。但它们可以被任何实现 PSR 接口类似工厂所替代。最后一个参数是配置。

配置

可能的配置

  • apiKey (字符串): 用于搜索和摄取 API。
  • database (字符串): 用于摄取 API。
  • infoApiEndpoint (字符串,有效 URI): 搜索 API 信息端点。
  • searchApiEndpoint (字符串,有效 URI): 搜索 API 端点。
  • facetApiEndpoint (字符串,有效 URI): 搜索 API 面板端点。
  • tokenApiEndpoint (字符串,有效 URI): 授权/令牌 API 的端点。
  • consumerKey (字符串): 用于授权/令牌 API。
  • consumerSecret (字符串): 用于授权/令牌 API。
  • textIngestionApiEndpoint (字符串,有效 URI): 用于摄取文本的摄取 API 端点。
  • fileIngestionApiEndpoint (字符串,有效 URI): 用于摄取文件的摄取 API 端点。
  • deleteApiEndpoint (字符串,有效 URI): 从索引中删除文档的摄取 API 端点。

服务器信息

$response = $client->getInfo();

将返回有关 Europa Search 服务器可用性和 API 版本的信息。

搜索

简单

$response = $client->search('something to search');

可以通过传递额外的参数来微调搜索。请检查 \OpenEuropa\EuropaSearchClient\Contract\ClientInterface::search() 获取参数的完整列表。响应是一个 \OpenEuropa\EuropaSearchClient\Model\Search 对象。

面板

$response = $client->getFacets('something to search');

可以通过传递额外的参数来微调面板搜索。请检查 \OpenEuropa\EuropaSearchClient\Contract\ClientInterface::getFacets() 获取参数的完整列表。响应是一个 \OpenEuropa\EuropaSearchClient\Model\Facets 对象。

摄取

文本

$response = $client->ingestText('http://example.com/page/to/be/ingested', 'text to be ingested/index');

请检查 \OpenEuropa\EuropaSearchClient\Contract\ClientInterface::ingestText() 获取参数的完整列表。响应是一个 \OpenEuropa\EuropaSearchClient\Model\Ingestion 对象。

文件

$binaryString = file_get_contents(...);
$client->ingestFile('http://example.com/file/to/be/ingested', $binaryString);

请检查 \OpenEuropa\EuropaSearchClient\Contract\ClientInterface::ingestFile() 获取参数的完整列表。响应是一个 \OpenEuropa\EuropaSearchClient\Model\Ingestion 对象。

删除文档

$success = $client->deleteDocument('referenceID');

该函数返回一个布尔值,指示操作是否成功。

贡献

请阅读 完整文档 了解我们的行为准则以及向我们提交拉取请求的流程。

版本控制

我们使用 SemVer 进行版本控制。