如何解决如何触发特定的Google自定义搜索引擎优化标签?
| 当前,我们的组织正在使用Google自定义搜索引擎来提供自动建议,并且在我们的CSE中配置了大约3个优化标签。以前,我们使用WebSearch和SearchControl,并且WebSearch具有setSiteRestriction方法,该方法使我们可以专门选择优化标签: -http://code.google.com/apis/websearch/docs/reference.html#_class_GwebSearch 先前的代码示例:var searchControl = new google.search.SearchControl();
var webSearch = new google.search.WebSearch();
//Refinement allows us to tell Google which specific sites to search
var refinement=\"Support\";
//filter custom search and currently there are 3 refinements
(some other variables declaration here including \'product\')
switch(product)
{
case \"10000\":
refinement = \"Support1\";
break;
case \"10200\":
refinement = \"Support1\";
break;
case \"10001\":
refinement = \"Support2\";
break;
default:
break;
}
/*this is the code to fill in the custom search. The refinement was set above - either \"Support\",\"Support1\",or \"Support2\".*/
webSearch.setSiteRestriction(\'cseId\',refinement);
......
但是,当前我们正在迁移到CustomSearchControl工具以替换已弃用的WebSearch,但是显然我找不到任何方法来根据switch case语句的值来专门选择优化标签。非常感谢您在这里立即获得帮助,如果有相关文档可以为我指出。谢谢! :)
解决方法
使用customSearchControl时,可以在选项中设置优化标签。
这将
a)不将搜索中的其他细化限制为关键字您
可能添加了(\'more:\'+优化),并且
b)同时突出显示
优化选项卡,告诉用户您代表他们做了什么。
var customSearchOptions =
{ \'defaultToRefinement\' : \'refinement_label_name\' };
var customSearchControl =
new google.search.CustomSearchControl(\'YOUR_CSE_ID\',customSearchOptions);
“自定义搜索元素JavaScript API参考”中提到了defaultToRefinement参数。
以前,此答案是在这里介绍的。
, 得到了答案。在代码中添加了以下几行:
var customSearchControl = new google.search.CustomSearchControl(cseId);
customSearchControl.setSearchStartingCallback(this,function(control,searcher,query)
{
searcher.setQueryAddition(\'more:\' + refinement);
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。