谷歌搜索API没有给出结果

时间:2009-12-30 11:45:11

标签: asp.net api search

我在网站上使用Google Search API来生成网站的结果。(the site)问题是,它根本没有产生结果。如果我将站点限制更改为其他站点(例如wikipedia.org或其他任何站点),则会产生结果。

并非该网站未列出 - 当我在Google主页上搜索site:www.hinroengineering.com时,我会收到结果。

代码如下:

google.load('search', '1');

function OnLoad() {
    // Create a search control
    var searchControl = new google.search.SearchControl();

    // web search, open
    options = new google.search.SearcherOptions();
    options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);

    // Add in a WebSearch
    var webSearch = new google.search.WebSearch();

    // Restrict our search to pages from the current site only
    webSearch.setSiteRestriction('http://www.hinroengineering.com');
    webSearch.setUserDefinedLabel(" Search results  ");

    // Add the searcher to the SearchControl
    searchControl.addSearcher(webSearch, options);

    // tell the searcher to draw itself and tell it where to attach
    searchControl.draw(document.getElementById("SeachContent"));
    searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);

    // execute an inital search
    searchControl.execute(CurrentSearchTerm);
    //alert(webSearch.results.length);

}

google.setOnLoadCallback(OnLoad);

1 个答案:

答案 0 :(得分:0)

您是否尝试从setSiteRestriction删除HTTP部分? Google文档似乎使用约定setSiteRestriction("domain.com")而没有任何协议:

http://code.google.com/apis/ajaxsearch/documentation/