按日期对 Google 自定义搜索结果进行排序

发布于 2024-11-10 08:11:35 字数 1402 浏览 3 评论 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);

也许按属性排序不起作用,因为我们不这样做我们的网络文档中没有声明属性。那么,有没有其他方法可以让我们告诉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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黒涩兲箜 2024-11-17 08:11:35

我遇到了以下内容:

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

如果问题仍然存在,希望这会有所帮助。

I came across the following:

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

Hope this will help if the problem is still there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文