Tôi mới dùng Java và Lucene. Mã của tôi nhận được một dòng từ một tệp và lưu trữ nó trong Lucene Index. Nhưng khi tôi tạo một IndexReader
để tìm kiếm và đọc từ chỉ mục, nó sẽ đưa ra một ngoại lệ.org.apache.lucene.index.IndexNotFoundException: không tìm thấy phân đoạn * nào trong org.apache.lucene.store.RAMDirectory
Mã java của tôi bên dưới. Vào việc tạo ra các IndexReader
nó ném một 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);
}
tôi áp dụng giải pháp này và nó làm việc. –