我想从谷歌自定义搜索中删除所有包含 PPT、DOC、PDF 的非 HTML 内容页面。我在自定义搜索引擎中尝试了各种 url 模式,但它仍然在搜索结果中返回 pdf 和 ppt。
我正在使用 Google 自定义搜索 API 来搜索图像。当我请求图像时,搜索结果始终为 0。我正在关注以下链接中的文档:
https://developers.google.com/custom-search/json-api/v1/reference/cse/list
根据文档,通过指定 searchType=images,api 只查找图像。
这是我的网址的样子:
结果如下所示:
{
"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 - cars",
"totalResults": "0",
"searchTerms": "cars",
"count": 10,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "017576662512468239146:omuauf_lfve",
"searchType": "image"
}
]
},
"searchInformation": {
"searchTime": 0.049329,
"formattedSearchTime": "0.05",
"totalResults": "0",
"formattedTotalResults": "0"
}
}
Run Code Online (Sandbox Code Playgroud)
如果我从请求中删除 searchType,我会以网页的形式返回结果。这里有什么问题?
我正在使用Google自定义搜索引擎及其新的自动完成功能.我希望在页面本身加载后加载整个javascript.原始的Google代码是这样的:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('search', '1');
google.setOnLoadCallback(function() {
google.search.CustomSearchControl.attachAutoCompletion(
'some-long-unique-id',
document.getElementById('q'),
'cse-search-box');
});
</script>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=cs"></script>
Run Code Online (Sandbox Code Playgroud)
我已经使用关于JS动态加载的教程将此代码转换为此代码:
(function() {
var goog = document.createElement('script'); goog.type = 'text/javascript';
goog.src = 'http://www.google.com/jsapi';
var cse = document.createElement('script'); cse.type = 'text/javascript';
cse.src = 'http://www.google.com/cse/brand?form=cse-search-box&lang=cs';
goog.onload = function() {
google.load('search', '1');
google.setOnLoadCallback(function() {
google.search.CustomSearchControl.attachAutoCompletion(
'some-long-unique-id',
document.getElementById('q'),
'cse-search-box');
});
};
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(cse, s);
s.parentNode.insertBefore(goog, s);
})();
Run Code Online (Sandbox Code Playgroud)
好吧,即使我认为我的解决方案应该可行(谷歌改变他们的分析按需异步代码的方式相同),但事实并非如此.页面加载正常,一旦CSE加载,页面就会变为空白.什么东西清除DOM,我想它是某种"谷歌的东西"?有人能否解决这个问题,可能还有一个有效的解决方案?
谢谢
我写的程序需要执行复杂的搜索查询.一个例子是
(蓝色和牛仔裤和不(便宜||昂贵)).我怎样才能做到这一点.我知道有一些参数,如hq和exclude和orTerms(或只是布尔运算符),但我不知道如何组合它们,或者它们是否可以组合起来.
谢谢一堆
我不确定我做错了什么但是我在这个网站上设置的谷歌自定义搜索并没有按照我需要的方式工作.我想要的是在页面中显示结果,当搜索将我带到页面时,结果出于某种原因出现在弹出窗口中.
这就是我所拥有的:
<script>
(function () {
var cx = '[hidden]';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:searchbox-only linktarget="_self" resultsUrl="/HomePage/Search-Results"></gcse:searchbox-only>
Run Code Online (Sandbox Code Playgroud)
我尝试使用_parent进行linktarget,但这也没有解决问题.有没有办法禁用此自定义搜索在弹出窗口中打开结果?
我正在使用GCSE的基本代码和标准"紧凑"主题:
<script>
(function() {
var cx = '111111111111111111111:11111111111';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
Run Code Online (Sandbox Code Playgroud)
这会将输入按钮呈现为:
<td class="gsc-search-button">
<input type="image" src="http://www.google.com/uds/css/v2/search_box_icon.png" class="gsc-search-button gsc-search-button-v2" title="search">
</td>
Run Code Online (Sandbox Code Playgroud)
我希望它是这样的
<td class="gsc-search-button">
<input type="button" value="search" title="search">
</td>
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄明白该怎么做.这可能吗?
我正在使用自定义搜索引擎(CSE)通过JSON API玩Google Custom Search API.我成功地获得了搜索结果,但我对如何获得搜索结果一无所知nextPageToken.
https://www.googleapis.com/customsearch/v1?key=MY_API_KEY&cx=MY_SEARCH_ENGINE_ID&q=Testing
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": {
"nextPage": [
{
"title": "Google Custom Search - Testing",
"totalResults": "2900",
"searchTerms": "Testing",
"count": 10,
"startIndex": 11,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "MY_SEARCH_ENGINE_ID"
}
],
"request": [
{
"title": "Google Custom Search - Testing",
"totalResults": "2900",
"searchTerms": "Testing",
"count": 10,
"startIndex": 1,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "MY_SEARCH_ENGINE_ID"
}
]
},
"context": {
"title": "Test …Run Code Online (Sandbox Code Playgroud) Google上次查看时更新了自定义搜索代码.这是我们的工作代码:
<script>
(function () {
var cx = '011561302208175438083:iegdgk3oox8';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
</script>
...
<gcse:search></gcse:search>
Run Code Online (Sandbox Code Playgroud)
我们想知道的是,当页面加载时,我们如何使此搜索框自动搜索值?
我的页面顶部有一个GET表单,但尚未配置.我所拥有的就是:
<div class="top-search">
<form method="get" id="searchform" action="#">
<div>
<input type="text" value="Search..." name="s" id="s" onfocus="defaultInput(this)" onblur="clearInput(this)" />
<input type="submit" id="searchsubmit" value=" " />
</div>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
如何操纵此操作才能使用Google CSE?
我正在尝试在我们的帮助中心添加Google自定义搜索.功能还可以,但造型非常错误.
我很确定一些CSS必须覆盖/干扰Google样式,但我似乎无法找出哪些(表格我猜).
进一步来说:
这是我正在使用的沙箱的链接,搜索栏位于标题下方的容器中:https://acrolinx1429009760.zendesk.com/hc
旁注:我只能访问Zendesk的一个主要CSS文件.
非常感谢任何帮助,谢谢.
javascript ×4
css ×1
forms ×1
html ×1
json ×1
ondemand ×1
parameters ×1
php ×1
sitecore ×1
zendesk ×1