0
我正在遷移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按日期對搜索結果進行排序?