如何触发特定的Google自定义搜索引擎优化标签? [英] How to trigger specific Google Custom Search Engine refinement label?

查看:86
本文介绍了如何触发特定的Google自定义搜索引擎优化标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我们的组织正在使用Google自定义搜索引擎来提供自动建议,并且在我们的CSE中配置了大约3个优化标签.以前,我们使用WebSearch和SearchControl,并且WebSearch具有setSiteRestriction方法,该方法使我们可以专门选择优化标签: - http://code.google.com/apis/websearch/docs/reference.html#_class_GwebSearch

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

先前的代码示例:

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

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! :)

推荐答案

得到答案.在代码中添加了以下几行:

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);
});

这篇关于如何触发特定的Google自定义搜索引擎优化标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆