`
liuInsect
  • 浏览: 133371 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

请您先登录,才能继续操作

lucene RAMDirectory org.apache.lucene.index.IndexNotFoundException

阅读更多

lucene   RAMDirectory org.apache.lucene.index.IndexNotFoundException

 

今天在使用lucene的时候遇见这个异常:

org.apache.lucene.index.IndexNotFoundException: no segments* file found in  org.apache.lucene.store.RAMDirectory@149b290 lockFactory=org.apache.lucene.store.SingleInstanceLockFactory@16a38b5: files: [] at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:712) at org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:75) at org.apache.lucene.index.IndexReader.open(IndexReader.java:462) at org.apache.lucene.index.IndexReader.open(IndexReader.java:322) at org.apache.lucene.search.IndexSearcher.<init>(IndexSearcher.java:93) at service.IndexServiceImpl.searchByboolean(IndexServiceImpl.java:136) at service.IndexServiceImpl.byBooleanQueryFromM(IndexServiceImpl.java:107) at test.IndexTest.testIndexCreateImMAndSearch(IndexTest.java:116) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


其实问题很简单....  (但是百度,谷歌却没定点痕迹 告诉我怎么做...)
这里是创建内存索引的地方:
writer = new IndexWriter(new RAMDirectory (), indexConfig);
 
实例化一个IndexWriter.. 其中的RAMDirectory  是新实例化的:

好.在读取内存索引的语句是:
searcher = new IndexSearcher( new  RAMDirectory());
 
注意:这里产生了两个 RAMDirectory ..就是这里出现的问题...

解决方法很简单,用单例模式,保证是同一个引用就好:
	ramDir = IndexFactroy.getRAMDirtoryInstance();
				writer = new IndexWriter(ramDir , indexConfig);
 

分享到:
评论

相关推荐

    lucene基本包

    Lucene,作为Apache软件基金会的一个顶级项目,是一个高度成熟、广泛使用的全文检索引擎架构。它为开发者提供了一套强大的工具,用于在各种应用中实现高效的全文搜索功能。这个“lucene基本包”包含了Lucene的核心...

    lucene简单代码列子

    import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org....

    lucene练习代码

    import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; public class Indexer { public static void main(String[] args) ...

    Lucene建立索引及查询包含“java”关键字 示例代码

    import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import java.nio.file.Paths; public class IndexingExample { ...

    Lucene之Helloworld

    import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; public class HelloWorldIndexer { public static void main...

    lucene for java 简单demo

    import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org....

    lucene,lucene教程,lucene讲解

    org.apache.lucene.index.IndexWriter public abstract class Directory org.apache.lucene.store.Directory public abstract class Analyzer org.apache.lucene.analysis.Analyzer public final class ...

    lucene示例代码

    import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; public class LuceneExample { public static void main(String[]...

    Lucene中文分词组件 JE-Analysis 1.4.0

    import org.apache.lucene.index.TermPositionVector; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.Hits; import org.apache.lucene.search.IndexSearcher; import org...

    simple_02.rar

    import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; Directory directory = new RAMDirectory(); IndexWriterConfig ...

    lucene-6.5.1

    import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import...

    第一个lucene程序

    import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org....

    Lucene全文检索

    import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; public class LuceneDemo { public static void main(String[] ...

    最新版linux lucene-8.10.0.tgz

    Linux Lucene 8.10.0是Apache Lucene项目的一个关键版本,它是一个高性能、全功能的文本搜索库,广泛应用于Java开发中。Lucene提供了丰富的搜索功能,包括全文检索、高级分析器、索引优化等,为开发者构建复杂的搜索...

    Lucene索引器实例

    import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; public class LuceneIndexExample { public static void main...

    Lucene.2.0.API

    《Lucene.2.0.API》是关于开源全文搜索引擎库Lucene的一个重要参考资料,它详尽地记录了Lucene 2.0版本的API接口及其使用方法。Lucene是一个由Apache软件基金会开发的Java全文检索库,它提供了高性能、可扩展的文本...

    lucene3.0使用介绍及实例

    import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; public class LuceneExample { public static void main(String[] args)...

    lucene核心资源包以及lucene的api

    - **IndexWriter API**: 如`org.apache.lucene.index.IndexWriter`,提供了添加、删除、优化索引的方法,如`addDocument(Document doc)`和`deleteDocuments(Term term)`。 - **Query API**: 如`org.apache.lucene....

    Linux源码剖析

    - **`org.apache.lucene.index.IndexWriter`**:索引的主要入口点,用于添加、删除文档,以及控制何时刷新或优化索引。 - **`org.apache.lucene.index.DocumentsWriter`**:负责将文档写入索引的内部类。 - **`org....

Global site tag (gtag.js) - Google Analytics