SynonymIndexBuilder { public int deleteDocumentByWord(String word) throws IOException { TopDocs docs = searchDocumentByWord(word); if (docs.totalHits.value == 0) { error.set(false, Messages.getString("SynonymIndexBuilder.doesnotExsit", word)); return 0; } else if (docs.totalHits.value == 1) { getWriter().deleteDocuments(new Term(SynonymIndexSearcher.F_WORDTERM, word.trim().toLowerCase())); return 1; } else { error.set(false, Messages.getString("SynonymIndexBuilder.documents", docs.totalHits, word)); } return 0; } SynonymIndexBuilder(); Error getError(); void setSynonymSeparator(char synonymSeparator); void initIndexInFS(String path); boolean insertDocument(String word, String synonyms); boolean insertDocumentIfNotExists(String word, String synonyms); int updateDocument(String word, String synonyms); int deleteDocumentByWord(String word); void deleteAllDocuments(); int addSynonymToDocument(String word, String newSynonym); int removeSynonymFromDocument(String word, String synonymToDelete); boolean deleteIndexFromFS(String path); void closeIndex(); void commit(); Analyzer getAnalyzer(); int getNumDocs();  }
@Test public void testDeleteDocumentByWord() throws IOException { printLineToConsole("\n---------------Test deleteDocument---------------"); SynonymIndexBuilder builder = createNewIndexBuilder(INDEX_PATH); insertDocuments(builder); SynonymIndexSearcher searcher = getSearcher(builder); int docCount = searcher.getNumDocs(); assertEquals(1, searcher.searchDocumentByWord("IAIDQ").totalHits.value); searcher.close(); builder.deleteDocumentByWord("IAIDQ"); builder.commit(); searcher = getSearcher(builder); assertEquals(docCount - 1, searcher.getNumDocs()); searcher.close(); builder.deleteDocumentByWord("random"); builder.commit(); searcher = getSearcher(builder); assertEquals(docCount - 1, searcher.getNumDocs()); searcher.close(); builder.closeIndex(); }