【问题标题】:Hibernate-Search and Lucene 3.5 SpellCheckerHibernate-Search 和 Lucene 3.5 拼写检查器
【发布时间】:2012-12-15 23:11:36
【问题描述】:

我正在使用带有 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);

【问题讨论】:

    标签: lucene hibernate-search


    【解决方案1】:

    找到了解决办法。顺序很重要。

    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);
    

    【讨论】:

    • 我认为问题在于一次打开多个 IndexWriters?
    • 正确。打开阅读器首先解决了这个问题,因为它没有获得锁。
    猜你喜欢
    • 1970-01-01
    • 2011-12-27
    • 2011-09-23
    • 1970-01-01
    • 2012-07-18
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多