如何解决按日期对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,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按日期对搜索结果进行排序吗?
解决方法
我遇到以下问题:
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);
希望如果问题仍然存在,将对您有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。