List of usage examples for org.apache.lucene.search.spell SpellChecker SpellChecker
public SpellChecker(Directory spellIndex) throws IOException
From source file:prman.model.SpellCheckManager.java
License:Open Source License
public void indexDictionary(Locale loc, InputStream[] words, String encoding) throws IOException { // unindexDictionary(loc); File fdir = new File(DIR, loc.toString()); fdir.mkdirs();// w w w . j a va2 s .co m // File[] contents = fdir.listFiles(); // for (int iCnt=0; iCnt<contents.length; iCnt++) // { // contents[iCnt].delete(); // } FSDirectory dir = FSDirectory.getDirectory(fdir, false); SpellChecker sc = new SpellChecker(dir); for (int iCnt = 0; iCnt < words.length; iCnt++) { PlainTextDictionary dictio = new PlainTextDictionary(words[iCnt], encoding); sc.indexDictionnary(dictio); } }
From source file:resource.IndexFiles.java
License:Apache License
private static void createDictionary(Analyzer analyzer) throws IOException { Directory dictionaryDir = FSDirectory.open(new File(DICTIONARY_PATH)); Directory indexDir = FSDirectory.open(new File(INDEX_PATH)); IndexReader reader = DirectoryReader.open(indexDir); Dictionary dictionary = new LuceneDictionary(reader, "contents"); IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_47, analyzer); SpellChecker spellChecker = new SpellChecker(dictionaryDir); spellChecker.indexDictionary(dictionary, iwc, false); spellChecker.close();//from w w w . ja v a2s. c o m }