【问题标题】:Image search returns no results图片搜索不返回任何结果
【发布时间】:2012-05-13 07:05:56
【问题描述】:

我的 Mac 最近“退役”了,所以我成功地将我的 Rails 2.3.8 应用程序移植到了 Windows 上的 Ubuntu 安装。一切正常,除了现在我使用 Google 自定义搜索 (CSE) 进行图像搜索时没有得到任何结果。

我有一个有效的 API 密钥和一个唯一的自定义搜索 ID - 这已得到确认,因为我在使用 CSE 执行常规“网络”搜索时得到了结果。我也在每日请求限制之内。我还仔细检查了 API 参考,以确保发布的语法没有改变,也没有改变。

我发出以下请求:

result_count=10
query='apple'

1) 网页搜索(产生结果) - - - - - - - - - - - - - - - - - - - - - - - - - - - -

type=''
url="https://www.googleapis.com/customsearch/v1?key=#{ENV['GOOGLE_KEY']}&cx=#{ENV['GOOGLE_SEARCH_ID']}#{type}&alt=json&num=#{result_count}&q=#{query}"

RESULT => 正如预期的那样,包含 10 个项目/结果的 JSON 格式字符串

2) 图片搜索(无论查询如何都没有结果) - - - - - - - - - - - - - - - -

type='&searchType=image'
url="https://www.googleapis.com/customsearch/v1?key=#{ENV['GOOGLE_KEY']}&cx=#{ENV['GOOGLE_SEARCH_ID']}#{type}&alt=json&num=#{result_count}&q=#{query}"

RESULT => 包含 0 个项目/结果的 JSON 格式字符串,如下所示:

{
 "kind": "customsearch#search",
 "url": {
  "type": "application/json",
  "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
 },
 "queries": {
  "request": [
   {
    "title": "Google Custom Search - apple",
    "totalResults": "0",
    "searchTerms": "apple",
    "count": 10,
    "inputEncoding": "utf8",
    "outputEncoding": "utf8",
    "safe": "off",
    "cx": "my_private_cx_id",
    "searchType": "image"
   }
  ]
 },
 "searchInformation": {
  "searchTime": 0.023136,
  "formattedSearchTime": "0.02",
  "totalResults": "0",
  "formattedTotalResults": "0"
 }
}

在我移植应用程序之前,图像搜索一直有效 - 我不知道我错过了什么,但我怀疑这是一个小疏忽。

【问题讨论】:

    标签: ruby-on-rails google-search-api


    【解决方案1】:

    我认为这可能是由于您没有为您的自定义搜索引擎启用图像搜索。您可以在 CSE 的控制台下启用它

    【讨论】:

    • 好东西。谢谢Redan - 我以某种方式错过了。现在都在工作。干杯。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    • 2020-03-16
    相关资源
    最近更新 更多