Google custom search 如何触发特定的谷歌自定义搜索引擎优化标签?

Google custom search 如何触发特定的谷歌自定义搜索引擎优化标签?,google-custom-search,Google Custom Search,目前,我们的组织正在使用谷歌定制搜索引擎提供自动建议,我们在CSE中配置了大约3个优化标签。以前,我们使用WebSearch和SearchControl,WebSearch有一个setSiteRestriction方法,允许我们专门选择一个优化标签: - 前面的代码示例: var searchControl = new google.search.SearchControl(); var webSearch = new google.search.WebSearch(); //Refinem

目前,我们的组织正在使用谷歌定制搜索引擎提供自动建议,我们在CSE中配置了大约3个优化标签。以前,我们使用WebSearch和SearchControl,WebSearch有一个setSiteRestriction方法,允许我们专门选择一个优化标签: -

前面的代码示例:

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语句的值专门选择优化标签。这里需要立即的帮助,如果有相关的文档,你们可以告诉我,我将不胜感激。谢谢!:)

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

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

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

a) 不要将搜索中的其他优化限制为搜索的关键字 可能添加了('more:'+细化),以及

b) 还强调 “优化”选项卡,告诉用户您代表他们做了什么

defaultToRefinement参数在自定义搜索元素中提到

在此之前,我们介绍了这个答案。

这几乎是可行的。。。您可以执行此操作,也可以只执行customSearchControl.execute(yourQuery+'更多:'+优化),但是,它不会突出显示“优化”选项卡来告诉用户您代表他们做了什么。调查,也许我会报个错误。
var customSearchOptions =
    { 'defaultToRefinement' : 'refinement_label_name' };

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