e.printStackTrace();
throw new ResourceIndexNotAvailableException("Unexpected SAX: " +
e.getMessage());
}
SearchResults results;
String type = wbRequest.get(WaybackConstants.REQUEST_TYPE);
if(type.equals(WaybackConstants.REQUEST_REPLAY_QUERY) ||
type.equals(WaybackConstants.REQUEST_URL_QUERY)) {
results = new CaptureSearchResults();
} else {
// TODO: this is wrong, but needs exploration into what NutchWax can actually do.
throw new BadQueryException("Unable to perform path prefix requests with this index type");
}
NodeList channel = getSearchChannel(document);
NodeList nodes = getSearchItems(document);
if (channel == null || channel.getLength() != 1) {
// TODO: better error for user:
throw new ResourceNotInArchiveException("No results for " +
requestUrl);
}
if (nodes == null) {
// TODO: better error for user:
throw new ResourceNotInArchiveException("No results for " +
requestUrl);
}
for (int i = 0; i < nodes.getLength(); i++) {
Element e = (Element) nodes.item(i);
SearchResult result = elementToSearchResult(e);
results.addSearchResult(result);
}
Element channelElement = (Element) channel.item(0);
results.putFilter(WaybackConstants.RESULTS_FIRST_RETURNED,
getNodeContent(channelElement,NUTCH_FIRST_RESULT));
results.putFilter(WaybackConstants.RESULTS_NUM_RESULTS,
getNodeContent(channelElement,NUTCH_NUM_RESULTS));
results.putFilter(WaybackConstants.RESULTS_NUM_RETURNED,
getNodeContent(channelElement,NUTCH_NUM_RETURNED));
results.putFilter(WaybackConstants.RESULTS_REQUESTED,
String.valueOf(wbRequest.getResultsPerPage()));
results.putFilter(WaybackConstants.REQUEST_START_DATE,
Timestamp.earliestTimestamp().getDateStr());
results.putFilter(WaybackConstants.REQUEST_END_DATE,
Timestamp.latestTimestamp().getDateStr());
return results;
}