existStartDate=false; // BUG 120608
startDateStr = Timestamp.earliestTimestamp().getDateStr();
}
int hitsPerPage = wbRequest.getResultsPerPage();
if(hitsPerPage < 1) {
throw new BadQueryException("Hits per page must be positive");
}
if(hitsPerPage > maxRecords) {
throw new BadQueryException("Hits per page must be less than " +
maxRecords);
}
int start = (wbRequest.getPageNum()-1) * hitsPerPage;
/* BUG 0000155 */
String multDet = wbRequest.get(WaybackConstants.REQUEST_MULT_DETAILS);
String docId = wbRequest.get(WaybackConstants.REQUEST_DOC_ID);
String indexId = wbRequest.get(WaybackConstants.REQUEST_INDEX_ID);
/* BUG 0000155 */
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");