0

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?

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 回答