lucene:no segments* file found in org.apache.lucene.store.FSDirectory@异常
[*]目的:我想把内存中的索引合并到磁盘文件中。
[*]异常:org.apache.lucene.index.IndexNotFoundException: no segments* file found in org.apache.lucene.store.RAMDirectory@1e94b0ca lockFactory=org.apache.lucene.store.SingleInstanceLockFactory@33e2ad75: files:
at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:741)
at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:630)
at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:343)
at org.apache.lucene.index.IndexWriter.addIndexes(IndexWriter.java:2333)
at org.apache.lucene.demo.IKAnalyzerT.createIndex(IKAnalyzerT.java:45)
at org.apache.lucene.demo.IKAnalyzerT.main(IKAnalyzerT.java:58)
意思是:我在把内存索引合并到磁盘的时候 内存中没有索引文件。
我的解决方案参考: 在索引库没有建立并且没有索引文件的时候首先要commit一下让他建立一个
[*]public class X {
[*] public static void main(String[] args) throws Exception{
[*] Analyzer a = new StandardAnalyzer(Version.LUCENE_CURRENT);
[*] IndexDeletionPolicy commitDeletionPolicy = new SolrDeletionPolicy();
[*] FSDirectory directory = FSDirectory.open(new File("c:\\"));
[*]
[*] IndexWriterConfig config = new
[*] IndexWriterConfig(Version.LUCENE_CURRENT,a);
[*] config.setOpenMode(OpenMode.CREATE_OR_APPEND);
[*] config.setIndexDeletionPolicy(commitDeletionPolicy);
[*] IndexWriter writer = new IndexWriter(directory, config);
[*]
[*] // -----------------
[*] // 在索引库没有建立并且没有索引文件的时候首先要commit一下让他建立一个
[*] // 索引库的版本信息
[*] //writer.commit();
[*] // -----------------
[*]
[*] //如果第一次没有commit就打开一个索引读取器的话就会报异常
[*] IndexReader reader = IndexReader.open(directory);
[*] System.out.println(reader);
[*] //Exception in thread "main" org.apache.lucene.index.IndexNotFoundException: no segments* file found in org.apache.lucene.store.SimpleFSDirectory@C:\ lockFactory=org.apache.lucene.store.NativeFSLockFactory@15a8767: files:
[*] // at
[*] // org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:711)
[*] // at
[*] // org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:75)
[*] // at org.apache.lucene.index.IndexReader.open(IndexReader.java:428)
[*] // at org.apache.lucene.index.IndexReader.open(IndexReader.java:274)
[*] // at com.zyb.solrQuery.X.main(X.java:39)
[*] }
[*]}
页:
[1]