logger.debug("Unable to load content repository for site '{}'", site);
throw new ContentRepositoryUnavailableException();
}
// Specify which pages to load
SearchQuery query = new SearchQueryImpl(site);
query.withVersion(Resource.LIVE);
// Add the keywords (or)
for (String subject : subjects) {
query.withSubject(subject);
}
// Add the pagelets required on stage (and)
if (requiredPagelets.size() > 0) {
List<Pagelet> pagelets = new ArrayList<Pagelet>();
for (String headline : requiredPagelets) {
String[] parts = headline.split("/");
if (parts.length > 1) {
Pagelet pagelet = new PageletImpl(parts[0], parts[1]);
pagelets.add(pagelet);
}
}
query.withPagelets(All, pagelets.toArray(new Pagelet[pagelets.size()])).inStage();
}
// Order by date and limit the result set
query.sortByPublishingDate(SearchQuery.Order.Descending);
query.withLimit(count);
// Finally Load the pages
pages = repository.find(query);
}