如何触发特定的Google自定义搜索引擎细化标签?

发布于 2024-11-10 06:54:43 字数 1278 浏览 4 评论 0原文

目前,我们的组织正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹉夏雨初晴づ 2024-11-17 06:54:43

使用customSearchControl时,您可以在选项中设置细化标签。
这将

a) 不将搜索中的其他优化限制为您所使用的关键字
可能添加了('更多:'+细化),并且

b) 还突出显示
细化选项卡告诉用户您代表他们做了什么。

var customSearchOptions =
    { 'defaultToRefinement' : 'refinement_label_name' };

  var customSearchControl =
    new google.search.CustomSearchControl('YOUR_CSE_ID', customSearchOptions);

自定义搜索元素 中提到了 defaultToRefinement 参数JavaScript API 参考

此前,此处< /a>.

When using customSearchControl, you can set the refinement label in the options.
This will

a) not restrict other refinements in your search to the keywords you
may have added with ('more: ' + refinement), and

b) also highlight
the refinement tab to tell the user what you did on their behalf.

var customSearchOptions =
    { 'defaultToRefinement' : 'refinement_label_name' };

  var customSearchControl =
    new google.search.CustomSearchControl('YOUR_CSE_ID', customSearchOptions);

The defaultToRefinement parameter is mentioned in the Custom Search Element JavaScript API Reference.

Previously, this answer was introduced here.

一花一树开 2024-11-17 06:54:43

得到答案了。将以下行添加到代码中:

var customSearchControl = new google.search.CustomSearchControl(cseId);
customSearchControl.setSearchStartingCallback(this, function(control, searcher, query) 
{
      searcher.setQueryAddition('more:' + refinement);
});

Got the answer. Appended the following lines to the code:

var customSearchControl = new google.search.CustomSearchControl(cseId);
customSearchControl.setSearchStartingCallback(this, function(control, searcher, query) 
{
      searcher.setQueryAddition('more:' + refinement);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文