我从 Google 文档中复制了大部分代码,然后使用文档来设置过滤器。
- 我没有收到任何错误
- 但是 FILETYPE_PNG 不起作用(
the filetype never gets restricted)
我使用 了 https://developers.google.com/custom-search/docs/structured_search#filetype
有人知道代码有什么问题吗?
我也尝试过searcher.execute("Kobe Bryant");
- 但它仍然不仅限于 PNG。
google.load('search', '1', {language: 'en', style: google.loader.themes.MINIMALIST});
google.setOnLoadCallback(function() {
var customSearchOptions = {};
var orderByOptions = {};
orderByOptions['keys'] = [{label: 'Relevance', key: ''} , {label: 'Date', key: 'date'}];
customSearchOptions['enableOrderBy'] = true;
customSearchOptions['orderByOptions'] = orderByOptions;
var imageSearchOptions = {};
//imageSearchOptions['layout'] = LAYOUT_POPUP; -- layout popup causing errors for some reason
customSearchOptions['enableImageSearch'] = true;
customSearchOptions['disableWebSearch'] = true;
var customSearchControl = new google.search.CustomSearchControl('Youaintfindingoutwhatthisis', customSearchOptions);
customSearchControl.setResultSetSize(google.search.Search.SMALL_RESULTSET);
var searcher = customSearchControl.getImageSearcher();
searcher.setRestriction(
customSearchControl.getImageSearcher.RESTRICT_FILETYPE,
customSearchControl.getImageSearcher.FILETYPE_PNG
);
var options = new google.search.DrawOptions();
options.setAutoComplete(true);
customSearchControl.draw('cse', options);
}, true);
更新
请看下面我的回答
仍然不知道 LAYOUT_POPUP 是怎么回事 - 我在这里收到一个未定义的错误