我正在迁移Google自定义搜索引擎以使用CustomSearchControl来替换已弃用的WebSearch API,其中一个要求是按日期对建议结果进行排序。但到目前为止,我无法弄清楚如何告知Google在返回建议之前按最新日期对结果进行排序。示例代码如下:
var refinement="Support";
.....
switch(product)
{
case "10000":
refinement = "Support1";
break;
case "10002":
refinement = "Support1";
break;
case "10001":
refinement = "Support2";
break;
default:
break;
}
var customSearchControl = new google.search.CustomSearchControl('cseId');
customSearchControl.setSearchStartingCallback(this, function(control, searcher, query) {
searcher.setQueryAddition('more:' + refinement);
});
customSearchControl.setResultSetSize(7);
customSearchControl.draw('entries');
......
我已尝试使用新近度标签对结果进行排序,但它不起作用:
customSearchControl.setSearchStartingCallback(this, function(control, searcher, query) {
//searcher.setQueryAddition('more:recent3');
searcher.setQueryAddition('more:' + refinement + ', more:recent3');
});
我也尝试按属性排序,但它也不起作用:
var options = {};
options[google.search.Search.RESTRICT_EXTENDED_ARGS] = {'sort': 'date-sdate:d:s'}; //Tried to use other date format but it doesn't help
var customSearchControl = new google.search.CustomSearchControl('cseId', options);
也许按属性排序不起作用,因为我们没有在Web文档中声明的属性。那么,还有其他方法可以让我们告诉Google按日期对搜索结果进行排序吗?
答案 0 :(得分:2)
我遇到了以下情况:
http://code.google.com/intl/nl-NL/apis/customsearch/docs/js/cselement-reference.html
options[google.search.Search.RESTRICT_EXTENDED_ARGS] = {
'lr': 'lang_it',
'sort': 'date'
};
var customSearchControl = new google.search.CustomSearchControl(id, options);
希望如果问题仍然存在,这将有所帮助。