gpt4 book ai didi

java - org.apache.lucene.index.IndexNotFoundException : no segments* file found in org. apache.lucene.store.RAMDirectory

转载 作者:太空狗 更新时间:2023-10-29 22:48:58 25 4
gpt4 key购买 nike

我是 Java 和 Lucene 的新手。我的代码从文件中获取一行并将其存储在 Lucene Index 中。但是当我创建一个 IndexReader 来搜索和读取索引时,它会抛出一个异常。

我的java代码如下。在创建 IndexReader 时它抛出一个 IndexNotFoundException

static String itemsfreq[];
static StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_35);
static IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_35, analyzer);

public static void index_data(Directory indexed_document,int doc_num,IndexWriter w) throws IOException
{
for(int i = 0;i < itemsfreq.length;i++)
{
Document doc = new Document();
doc.add(new Field(Integer.toString(doc_num)+","+itemsfreq[i],itemsfreq[i++], Field.Store.YES, Field.Index.ANALYZED));
w.addDocument(doc);
}
}
//Gets string from a file and insert it in INDEX named indexed_document
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new FileReader("fullText100.txt"));
String line;
int i = 0;
Directory indexed_document = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexed_document, config);
while((line=reader.readLine()) != null)
{
if(i == 1)
{
break;
}
itemsfreq = line.split(" ");
index_data(indexed_document,i,writer);
i++;
}

IndexReader r = IndexReader.open(indexed_document);
}

最佳答案

在使用阅读器打开索引之前,调用一次writer.commit()

关于java - org.apache.lucene.index.IndexNotFoundException : no segments* file found in org. apache.lucene.store.RAMDirectory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10460737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com