簡體   English   中英

Google自定義搜索排序日期范圍標准不起作用

[英]Google custom search sort date range criteria not working

在Google自定義搜索中,我們在sort參數中傳遞日期范圍條件

http://www.example.com/search?cx=xxxxxxxxxxxxxxxxxxxxx:yyyyyy_yyyyy&q=google&sort=date:r:20160304:20160505.
https://developers.google.com/custom-search/docs/structured_search#restrict_to_range

但是我們沒有按照日期范圍標准獲得預期結果。 調試代碼后,即使我們將sort參數傳遞給我們的搜索頁面網址,也不會將sort參數傳遞給自定義搜索網址。

Google自定義搜索網址:

https://cse.google.com/cse?q=google&r=m&cx=xxxxxxxxxxxxxxxxxxxxx:yyyyyy_yyyyy&fexp=20606&client=google-coop&hl=en&type=0&oe=UTF-8&ie=UTF-8&format=p4&ad=p4&nocache=1081472127237880&num=0&output=uds_ads_only&source=gcsc&v=3&allwcallad=1&adext=as1%2Csr1%2Cctc1&bsl=10&u_his=50&u_tz=330&dt=1472127237882&u_w=1366&u_h=768&biw=1349&bih=233&psw=1349&psh=233&frm=0&uio=uv3st16sd13sv13lhsl1sr1cc1-&jsv=14100&rurl=http%3A%2F%2Fwww.example.com%2Fsearch%3Fcx%xxxxxxxxxxxxxxxxxxxx_yyyyy%26q%3Dgoogle%26sort%3Ddate%253Ar%253A20160304%253A20160505

但是當我們嘗試使用排序日期范圍參數訪問直接API時,我們得到了預期的結果。

https://www.googleapis.com/customsearch/v1?q=google&cx=xxxxxxxxxxxxxxxxxxxxx:yyyyyy_yyyyy&sort=date%3Ar%3A20160701%3A20160724&key=<APIKEY>

我們正在使用Google自定義搜索V2實施。

謝謝,Anup

嘗試轉義作為查詢參數傳遞的所有特殊字符。 例如

>  - &lt;
<  - &gt;
&  - &amp;
'  - &#039;
'' - &#034;

這些編碼是這樣的。 你可以通過兩種方式逃脫它

  1. 顯式指定escapeXml = "**false**"作為默認值將為true。
  2. 如果您使用<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> ,請在JSP中添加url,然后通過調用${fn:escapeXml(myString)}

這似乎與您的url參數編碼有關。 它可能是雙重編碼的。

我認為在代碼中你為查詢參數執行任何轉義字符嘗試刪除該檢查

確保您使用的格式正確。

https://www.googleapis.com/customsearch/v1?key=INSERT_YOUR_API_KEY&cx=017576662512468239146:omuauf_lfve&q=searchterm&sort=document-weight

謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM