如何触发特定的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 的值专门选择细化标签案例陈述。这里需要立即帮助,如果有相关文档可以给我指点,我将不胜感激。谢谢! :)
Currently, our organization is using Google Custom Search engine to provide auto suggestion, and we have about 3 refinement labels configured in our CSE. Previously, we're using WebSearch and SearchControl, and the WebSearch has a setSiteRestriction method which allows us to specifically select a refinement label:
- http://code.google.com/apis/websearch/docs/reference.html#_class_GwebSearch
Previous code example:
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);
......
However, currently we're migrating to CustomSearchControl tool to replace the deprecated WebSearch, but apparently I couldn't find any way to specifically select a refinement label based on the value of switch case statement. Immediate help needed here, and if there's a relevant docs that you guys can point me to will be much appreciated. thanks! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用customSearchControl时,您可以在选项中设置细化标签。
这将
自定义搜索元素 中提到了 defaultToRefinement 参数JavaScript API 参考。
此前,此处< /a>.
When using customSearchControl, you can set the refinement label in the options.
This will
The defaultToRefinement parameter is mentioned in the Custom Search Element JavaScript API Reference.
Previously, this answer was introduced here.
得到答案了。将以下行添加到代码中:
Got the answer. Appended the following lines to the code: