int recovered = 0;
for (Pair<String, BoostedDocument> pair : allDocuments) {
logger.debug("Document found!");
String docId = pair.first();
BoostedDocument boostedDocument = pair.last();
Map<Integer, Double> doubleBoosts = Maps.newHashMap();
for (Entry<Integer, Float> entry : boostedDocument.getBoosts().entrySet()) {
doubleBoosts.put(entry.getKey(), Double.valueOf(entry.getValue()));
}
Map<String,String> categories = boostedDocument.getCategories();
int userTimestamp;
try {
userTimestamp = Integer.parseInt(boostedDocument.getDocument().getField("timestamp"));
} catch (NumberFormatException e) {
logger.warn("Invalid timestamp " + boostedDocument.getDocument().getField("timestamp") + " for document " + docId + " -- SKIPPING DOCUMENT");
continue;
}
recovered++;
if (onlyDynamicData) {
// this is only usefull for reddit, and only because it has an old version that doesn't recover variables from simpledb.
//System.out.println("Updating docid:" + docId);
client.updateBoost(docId, doubleBoosts);
client.updateTimestampBoost(docId, userTimestamp);
client.updateCategories(docId, categories);
} else {
//System.out.println("Adding docid:" + docId);
if (boostedDocument.getDocument().asMap().size() > 0) {
Document doc = new Document();
doc.set_fields(boostedDocument.getDocument().asMap());
client.addDoc(docId, doc, userTimestamp, doubleBoosts);
} else {
client.updateBoost(docId, doubleBoosts);
}
client.updateCategories(docId, categories);