我已经浏览过互联网,但我似乎无法使用正确的术语进行搜索。 我的问题是 Lucene 索引大小为 0kb 的空 _0.fdt 和 _0.fdx 文件。这意味着它没有索引我的数据。
这是我的代码:
private int indexDocs(String dataTmp){
// LETS START PROCESSING THE INDEXING OF CONTENTS OF THE DATA PASSED
// make a new, empty document
Document doc = new Document();
// Method variables
int trueValue=0;
String[] datas;
String[][] contents;
String[] contentArray;
// Setting single variable
String field="";
String inContent="";
long time;
// NOW LETS PROCESS
datas=dataReader(dataTmp); // Calling the data reader
contents=dataProcessor(datas); // Calling the contents retriever
// Now lets index each content retrieved
if(contents.length>0){
for(String[] content:contents){
// Now lets loop through each content to index
for(int i=0; i<content.length; i++){
contentArray=content[i].split("\\::::");
field=contentArray[0];
inContent=contentArray[1];
//System.out.println(field+" === "+inContent);
// NOW LETS INDEX DOCUMENT IN ITS APPROPRAITE FIELD
if(field.equals("contents") || field.equals("title") || field.equals("keywords")){
Field textField=new TextField(field, inContent, Field.Store.YES);
doc.add(textField);
}
else{
Field stringField = new StringField(field, inContent, Field.Store.YES);
doc.add(stringField);
}
} // End of loop
} // End of loop
// Here we try to index Date of time the index was logged
time=System.currentTimeMillis();
doc.add(new LongPoint("date", time));
// New index, so we just add the document (no old document can be there):
// System.out.println("adding " + file);
try {
//by a reader on the same index
writer.addDocument(doc);
// Now lets set the true
trueValue=1;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} // End of content check
// Now lets return value
return trueValue;
}
我不知道获取这种输出文件我做错了。我之前用 lucene 索引过数据,但我不能只看到代码的问题。 我试图单独循环遍历数组和索引中的内容,但没有得到索引记录。请帮我解决这个问题。
最佳答案
不知道你在哪里声明了 writer,但这通常发生在 writer 未关闭时,尝试在添加文档后关闭 writer
关于Java:Lucene 索引大小为 0kb 的空 _0.fdt 和 _0.fdx 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45807490/