谷歌cse自定义搜索daterestrict

时间:2016-10-12 20:09:44

标签: google-custom-search

我想将自定义搜索引擎(cse)的搜索结果限制为一天。

我在" dateRestrict"上找到了一些信息。参数在这里 https://developers.google.com/custom-search/json-api/v1/reference/cse/list

它也可以在api explorer中找到 https://developers.google.com/apis-explorer/#p/customsearch/v1/search.cse.list

如何将此参数传递给搜索选项?我一直试图将它们放在我认为可行的任何地方,但无济于事......

我已经找到了类似的问题,但答案只是转换到一个不同的api ....

<script type='text/javascript'>
    google.load('search', '1', {language: 'de', style: google.loader.themes.V2_DEFAULT});
    google.setOnLoadCallback(function() {
      var customSearchOptions = {};
      customSearchOptions[google.search.Search.RESTRICT_EXTENDED_ARGS] ={'as_sitesearch' : 'https://xy.com/'};
      var orderByOptions = {};
      orderByOptions['keys'] = [{label: 'Relevanz', key: ''} , {label: 'Datum', key: 'date'}];
      customSearchOptions['enableOrderBy'] = true;
      customSearchOptions['orderByOptions'] = orderByOptions;
      var customSearchControl =   new google.search.CustomSearchControl('mykeygoeshere', customSearchOptions);
      customSearchControl.setResultSetSize( google.search.Search.FILTERED_CSE_RESULTSET );
      customSearchControl.setLinkTarget( google.search.Search.LINK_TARGET_SELF );
      var options = new google.search.DrawOptions();
      var query = unescape(LTH.getUrlVars().searchfor);
      customSearchControl.draw('cse', options);          
      customSearchControl.execute(query);                    
    }, true);
  </script>**strong text**

1 个答案:

答案 0 :(得分:0)

可以在customSearchOptions中指定传递给cse的参数的选项。我之前尝试过这个,但参数名称与XML-API不同(感谢谷歌)

https://developers.google.com/custom-search/docs/js/cselement-reference#opt_options

https://developers.google.com/custom-search/docs/xml_results#WebSearch_Query_Parameter_Definitions

所以这终于有效了

    customSearchOptions[google.search.Search.RESTRICT_EXTENDED_ARGS] ={'as_sitesearch' : 'https://www.landestheater-linz.at/','as_qdr':'d100'};