我在Lucene 3.5中使用Hibernate搜索,并试图实现一个“你的意思是什么?”拼写检查器搜索。我想用索引作为字典。我遇到的问题是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);发布于 2012-12-16 15:46:02
找到了解决方案。秩序很重要。
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);https://stackoverflow.com/questions/13897033
复制相似问题