0

我正在使用带有 Lucene 3.5 的 Hibernate Search 并尝试实现“您的意思是?” 拼写检查搜索。我想将索引用作字典。我遇到的问题是 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);
4

1 回答 1

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);
于 2012-12-16T07:46:01.647 回答