gabrielbull/sitesearch

此包已被弃用且不再维护。未建议替代包。

Google Site Search自定义搜索PHP包装库

dev-master 2016-07-06 14:38 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:31:04 UTC


README

Build Status

使用Google自定义搜索引擎和Google Site Search账户的网站搜索引擎。

Google Site Search API

要使用Google Site Search API,您必须从Google获取搜索引擎ID

要求

此库使用PHP 5.3+。

安装

建议您通过composer安装PHP Google Site Search库。

{
    "require": {
        "gabrielbull/sitesearch": "dev-master"
    }
}

搜索

SiteSearch类允许您搜索Google自定义搜索引擎。您只需提供搜索引擎ID和一个查询即可。

示例

$id = "YOUR_SEARCH_ENGINE_ID";

$siteSearch = new SiteSearch($id);
$results = $siteSearch->search('kittens');

foreach($results as $result) {
    echo $result['title'];
}

或者

$id = "YOUR_SEARCH_ENGINE_ID";

foreach(SiteSearch::create($id)->search('cats') as $result) {
    echo $result['title'];
}

参数

搜索方法参数包括

  • value 搜索查询。
  • start 返回第一个结果的位置偏移量。
  • limit 返回的结果数量。

结果

搜索结果将包含以下参数

  • link 页面的链接。
  • title 页面的标题。
  • description 页面的描述。
  • lang 页面的语言。
  • image 与页面相关联的图像(src)。
  • thumbnail 图像的缩略图(src、宽度和高度)。