[求助]Lucene RAMDirectory写入FSDirectory没有异常,但是FSDirectory没有数据??
Lucene RAMDirectory写入FSDirectory没有异常,但是FSDirectory没有数据??
网上找了,好像很少有这现象,加了打印语句,程序没有走漏,但是最后的索引文件才48K,肯定是内存的数据没有写到文件了,请大侠指点下,短短几行的到吗,Lucene in Action 也是这样做的,怎么就出错了?
while(i < end)
{
int batEnd = i+indexBat;
try{
// Connection conn = DriverManager.getConnection(urlDB);
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery("select kindtag," +
"title,site,goods_id from goods where goods_id between " + String.valueOf(i)+" and "+String.valueOf(batEnd+1));
while( rs.next())
{
Document doc = new Document();
doc.add(new Field("kindtag", rs.getString("kindtag"), Field.Store.NO, Field.Index.TOKENIZED));
doc.add(new Field("title", rs.getString("title"), Field.Store.NO, Field.Index.TOKENIZED));
doc.add(new Field("site", rs.getString("site"), Field.Store.NO, Field.Index.NO_NORMS));
doc.add(new Field("gid", String.valueOf(rs.getString("goods_id")), Field.Store.YES, Field.Index.NO_NORMS));
ramWriter.addDocument(doc);
ramCount +=1;
}
if(ramCount >5000)
{
System.out.print("ss");//这个打印出来了,
ramWriter.flush();//网上看到有加这个,但是加与不加,都没有数据。
this.writer.addIndexesNoOptimize(new Directory[] {ramDir});
ramWriter.close();
writer.flush();//网上看到有加这个,但是加与不加,都没有数据。
ramWriter = new IndexWriter(this.ramDir, new PaodingAnalyzer(), true);
ramCount = 0;
}
}
...
}
[解决办法]
看了这行代码:if(ramCount >5000)
发现如果你的记录少于5000行的话,就不会建索引了吧,你的记录条数>5000吗?
还有,程序界面或者日志里面报什么异常错误吗?