Hibernate-Search и Lucene 3.5 SpellChecker

Я использую 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);

person Doug    schedule 15.12.2012    source источник


Ответы (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);
person Doug    schedule 16.12.2012
comment
Я так понимаю, проблема заключалась в одновременном открытии нескольких IndexWriters? - person femtoRgon; 16.12.2012
comment
Правильный. Открытие ридера сначала решило проблему, так как оно не получало блокировки. - person Doug; 10.03.2013