Hibernate-Search和Lucene 3.5 SpellChecker

时间:2012-12-15 23:11:37

标签: lucene hibernate-search

我正在使用Hibernate Search与Lucene 3.5并试图实现一个"你的意思是?"拼写检查。我想使用索引作为字典。我遇到的问题是indexDirectory的文档与当前的方法签名不匹配,我无法找到有关如何从任何其他来源实现的任何细节。谁能指出我正确的方向?这是我从方法签名本身解密的内容,但它只会导致锁定异常。

Directory directory = FSDirectory.open(FileUtils.toFile(new URL("file:lucene/indexes/")));

IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_35, new                StandardAnalyzer(Version.LUCENE_35));

IndexWriter indexWriter = new IndexWriter(directory, indexWriterConfig);
IndexReader indexReader = IndexReader.open(indexWriter, false);

this.spellChecker = new SpellChecker(directory);
this.spellChecker.indexDictionary(new LuceneDictionary(indexReader, "favorite"), indexWriterConfig, true);

1 个答案:

答案 0 :(得分:0)

找到解决方案。订单很重要。

Directory directory = FSDirectory.open(FileUtils.toFile(new URL("file:lucene/indexes/")));
this.spellChecker = new SpellChecker(directory);
IndexReader indexReader = IndexReader.open(directory, true);
LuceneDictionary dictionary = new LuceneDictionary(indexReader, "field");
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35));
this.spellChecker.indexDictionary(dictionary, indexWriterConfig, true);