目前,我们的组织正在使用 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) 不要将搜索中的其他细化限制为您所使用的关键字
可能添加了('更多:'+细化),并且
b) 还强调
细化选项卡告诉用户您代表他们做了什么。
var customSearchOptions =
{ 'defaultToRefinement' : 'refinement_label_name' };
var customSearchControl =
new google.search.CustomSearchControl('YOUR_CSE_ID', customSearchOptions);
自定义搜索元素中提到了 defaultToRefinement 参数JavaScript API 参考.
之前有介绍过这个答案here.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)