query.withFulltext(text.toString());
// Is it a page?
Formatter formatter = null;
try {
SearchResult result = repository.find(query);
// Format the output
formatter = new Formatter(System.out);
StringBuffer format = new StringBuffer();
int padding = Long.toString(result.getDocumentCount()).length();
format.append("%1$#").append(padding).append("s. %2$s\n");
// List results
int i = 1;
for (SearchResultItem item : result.getItems()) {
formatter.format(format.toString(), i++, item.getUrl());
}
System.out.println("Found " + result.getDocumentCount() + " results (" + result.getSearchTime() + " ms)");
} catch (ContentRepositoryException e) {
System.err.println("Error trying to access the content repository");
e.printStackTrace(System.err);
} finally {
IOUtils.closeQuietly(formatter);