@Override
public void run() {
long testStartTime = System.nanoTime();
Session session = this.getSession();
// Database db = session.getDatabase("", "events4.nsf");
Database db = session.getDatabase("", "events4.nsf");
// System.out.println("Starting build of byMod view");
// long vStartTime = System.nanoTime();
// View newView = db.createView("ModTest", "SELECT @All");
// ViewColumn modCol = newView.createColumn(1, "Modified", "@Modified");
// modCol.setSorted(true);
// newView.refresh();
// long vEndTime = System.nanoTime();
// System.out.println("Completed building byModView in " + ((vEndTime - vStartTime) / 1000000) + "ms");
// IndexDatabase index = new IndexDatabase(session.getDatabase("", "redpill/index.nsf"));
// Document indexDoc = index.getDbDocument(db.getReplicaID());
// System.out.println("UNSORTED");
List<String> criteria = new ArrayList<String>();
// criteria.add("@doclength");
criteria.add("@modifieddate");
try {
DocumentSorter sorter = null;
// if (indexDoc.hasItem("DocumentSorter")) {
// sorter = indexDoc.getItemValue("DocumentSorter", DocumentSorter.class);
// sorter.setDatabase(db);
// System.out.println("Starting resort of " + sorter.getCount() + " documents");
// } else {
DocumentCollection coll = db.getAllDocuments();
sorter = new DocumentSorter(coll, criteria);
System.out.println("Starting resort of " + coll.getCount() + " documents");
// }
// System.out.println("SORTING...");