private IndexManager() { //to force reindexing, uncomment this line //this.clearAll(); String datapath = "D:\\Data\\original"; docs = new List <DocumentWrapper>(); List <TextDocument> txtdocs = DirectoryReader.getDocuments(datapath); List <Document> dbDocs = DatabaseAdaptor.getAllDocuments(); bool isAllIndexed = true; //for each text document, search in the db for a document with the same path. if all documents are in the // database, then no need to reindex. foreach (TextDocument txtDoc in txtdocs) { // finding a document in the db with the same path means it is indexed Document doc = DatabaseAdaptor.findDocumentByPath(txtDoc.getPath()); if (doc == null) { isAllIndexed = false; break; } else { docs.Add(new DocumentWrapper(doc, txtDoc)); } } //there still a single case, if the database contains documents more than what we want to index, then reindex. if (isAllIndexed == false || dbDocs.Count > txtdocs.Count) { this.clearAll(); this.docs = new List <DocumentWrapper>(); foreach (TextDocument txtDoc in txtdocs) { DocumentWrapper wrapper = this.addDocument(txtDoc.getText(), txtDoc.getTitle(), txtDoc.getPath(), txtDoc.getDate()); this.indexDocument(wrapper); } } // in the following case, all documents are already indexed, so just load them }