if ((urlStr==null || urlStr.length()<=0) && (docId==null || indexId==null)) {
throw new BadQueryException("Url is empty.");
}
// Construct the search url.
MutableString ms = new MutableString(this.searchUrlBase)
.append("?query=");
// Add 'date:...+' to query string.
if (existStartDate || existEndDate) { // BUG wayback 0000051; if exist startDate OR endDate
ms.append("date%3A").append(startDateStr).append('-').append(endDateStr);
}
else if (exactDateStr!=null) { // BUG wayback 0000153
ms.append("closestdate%3A").append(exactDateStr);
}
ms.append('+');
// Add 'url:URL'.
if(wbRequest.get(WaybackConstants.REQUEST_TYPE).equals(
WaybackConstants.REQUEST_URL_PREFIX_QUERY)) {
ms.append("url%3A").append(urlStr);
} else {
try {
if (docId!=null && indexId!=null) {
// do nothing
}
else if (wbRequest.get(WaybackConstants.REQUEST_ALIASES)!=null && wbRequest.get(WaybackConstants.REQUEST_ALIASES).equals("true")) {
ms.append("exacturlexpand%3A").append(java.net.URLEncoder.encode(urlStr, "UTF-8"));
}
else {
URL url=null;
boolean error=false;
try {
url=new URL(urlStr);
}
catch (MalformedURLException e) {
error=true;
}
if (!error && !urlStr.endsWith("/") && url.getQuery()==null && url.getPath().indexOf('.')==-1) { // BUG nutchwax 0000357 - add also a "/" if the url's query is null and is not a file
ms.append("exacturlexpandmin%3A").append(java.net.URLEncoder.encode(urlStr, "UTF-8"));
}
else {
ms.append("exacturl%3A").append(java.net.URLEncoder.encode(urlStr, "UTF-8"));
}
}
}
catch (UnsupportedEncodingException e) {
throw new BadQueryException(e.toString());
}
catch (NullPointerException e) {
throw new BadQueryException(e.toString());
}
}
ms.append("&hitsPerPage=").append(hitsPerPage);
ms.append("&start=").append(start);
ms.append("&dedupField=site");
// As we are always searching agains an url, a
// higher perDup/Site will return just more versions
ms.append("&hitsPerDup=").append(hitsPerPage);
ms.append("&hitsPerSite=").append(hitsPerPage);
ms.append("&waybackQuery=true"); // indicates that this OpenSearch request came from wayback
/* BUG 0000155 */
if (multDet!=null) {
ms.append("&multDet=").append(multDet);
}
if (docId!=null) {
ms.append("&id=").append(docId);
}
if (indexId!=null) {
ms.append("&index=").append(indexId);
}
/* BUG 0000155 */
return ms.toString();
}