0

Google カスタム検索エンジンを移行して CustomSearchControl を使用し、非推奨の WebSearch API を置き換えているところです。要件の 1 つは、提案結果を日付で並べ替えることです。しかし、これまでのところ、提案を返す前に最新の日付で結果を並べ替えるよう 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 に指示できる方法は他にあるでしょうか?

4

1 に答える 1

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

問題が解決しない場合は、これが役立つことを願っています。

于 2012-01-27T10:06:40.453 に答える