在MMapDirectory中找不到段*文件

问题描述 投票:0回答:1

我想进行自动更正,但是当我运行代码出错时,我注意到DictionaryReaderLuceneDictionary都出了问题,但是当我使用Plaintextdictionary运行它时,它可以正常工作。我不知道怎么了。任何建议,将不胜感激。

输出错误:

org.apache.lucene.index.IndexNotFoundException:无细分*文件在发现MMapDirectory @ C:...lockFactory=org.apache.lucene.store.NativeFSLockFactory@1cd072a9:档案:[]个org.apache.lucene.index.SegmentInfos $ FindSegmentsFile.run(SegmentInfos.java:675)在org.apache.lucene.index.StandardDirectoryReader.open(StandardDirectoryReader.java:84)在org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:76)在org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:64)在CreateSpellCheckerIndex.main(test.java:42)

import java.io.IOException;
import java.nio.file.Paths;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.spell.LuceneDictionary;
import org.apache.lucene.search.spell.PlainTextDictionary;
import org.apache.lucene.search.spell.SpellChecker;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.Directory;


public class CreateSpellCheckerIndex {

  public static void main(String[] args) throws IOException {

    String indexDir = "/Index";
    String SpellCheckDir = "/Data";
    String indexField = "contains";
    String words="Data/words.txt";
    //Creating SpellCheck Index
    System.out.println("Now build SpellChecker index...");
    Directory dir = FSDirectory.open(Paths.get(SpellCheckDir));
    Directory dir2=FSDirectory.open(Paths.get(indexDir));

    SpellChecker spell = new SpellChecker(dir);     
    long startTime = System.currentTimeMillis();

    IndexWriterConfig config = new IndexWriterConfig(null);
    IndexReader r=DirectoryReader.open(dir2);

    try
    {
      LuceneDictionary dict = new LuceneDictionary(r,indexField);
      spell.indexDictionary(dict,config,true);
    }finally{
       r.close();
    }
    //Add words to SpellChecker Index
    //IndexWriterConfig config = new IndexWriterConfig(null);
    //spell.indexDictionary(new PlainTextDictionary(Paths.get(words)),config,false);  
    dir2.close();   
    dir.close();
    spell.close();
    long endTime = System.currentTimeMillis();
    System.out.println("  took " + (endTime-startTime) + " milliseconds");
  }
}
java lucene lucene.net spell-checking
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.