SynonymIndexBuilder { public boolean insertDocumentIfNotExists(String word, String synonyms) throws IOException { if (searchDocumentByWord(word).totalHits.value == 0) { getWriter().addDocument(generateDocument(word, synonyms)); return true; } error.set(false, Messages.getString("SynonymIndexBuilder.aDocument", word)); return false; } 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 testInsertDocumentIfNotExists() throws Exception { printLineToConsole("\n---------------Test addDocument------------------"); SynonymIndexBuilder builder = createNewIndexBuilder(INDEX_PATH); insertDocuments(builder); builder.insertDocumentIfNotExists("ADD", "This|is|a|new|document"); builder.commit(); SynonymIndexSearcher searcher = getSearcher(builder); assertEquals(synonyms.length + 1, searcher.getNumDocs()); builder.insertDocumentIfNotExists("ANPE", "This|is|an|existing|document"); builder.commit(); searcher.close(); searcher = getSearcher(builder); searcher.close(); assertEquals(synonyms.length + 1, searcher.getNumDocs()); builder.insertDocumentIfNotExists("Irish Bar Managers", "IBM"); builder.commit(); searcher = getSearcher(builder); assertEquals(synonyms.length + 2, searcher.getNumDocs()); searcher.close(); builder.closeIndex(); }