import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.spell.PlainTextDictionary;
import org.apache.lucene.search.spell.SpellChecker;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
IndexWriterConfig config=new IndexWriterConfig(Version.LUCENE_36, new StandardAnalyzer(Version.LUCENE_36));
//设置词典索引存放目录
SpellChecker sc=new SpellChecker(FSDirectory.open(new File("D:/Project/spelling/index")));
sc.indexDictionary(new PlainTextDictionary(new File("D:/Project/spelling/dict/spell.txt")), config, false);
// sc.clearIndex();
// sc.setAccuracy(0.01f);
// System.out.println(sc.exist("indes"));
String[] rs=sc.suggestSimilar("indes", 5);
System.out.println(Arrays.toString(rs));
}
}