开发者

Sort Google Custom Search Results by Date

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 f开发者_开发百科ormat 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜