按日期对 Google 自定义搜索结果进行排序
我正在迁移 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);
也许按属性排序不起作用,因为我们不这样做我们的网络文档中没有声明属性。那么,有没有其他方法可以让我们告诉Google按日期对搜索结果进行排序呢?
I'm in the middle of migrating Google Custom Search Engine to use the CustomSearchControl to replace the deprecated WebSearch API, and one of the requirement is to sort the suggestion results by date. But so far, I couldn't figure out how to tell Google to sort results by latest date before returning the suggestion. The sample code is as follows:
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');
......
I've tried the recency label to sort the results, but it doesn't work:
customSearchControl.setSearchStartingCallback(this, function(control, searcher, query) {
//searcher.setQueryAddition('more:recent3');
searcher.setQueryAddition('more:' + refinement + ', more:recent3');
});
And I also tried sorting by attributes but it's not working either:
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);
Perhaps sorting by attributes will not work because we don't have attributes declared in our web documentations. Thus, is there any other way that allows us to tell Google to sort the search results by date?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了以下内容:
http:// /code.google.com/intl/nl-NL/apis/customsearch/docs/js/cselement-reference.html
如果问题仍然存在,希望这会有所帮助。
I came across the following:
http://code.google.com/intl/nl-NL/apis/customsearch/docs/js/cselement-reference.html
Hope this will help if the problem is still there.