我有一个桌面应用程序,它实现了用于数据库搜索的 lucene 3.6.2 搜索引擎。该数据库包含具有日期和字符数据类型的列。某些列还可以包含空字段。Datetools 还用于将 Date 转换为 String 以供 Lucene 分析但是看起来当 lucene 无法将日期列中的空字段添加到 Document 容器以进行分析时。
我在下面展示代码片段:
doc = new Document();
if(rs.getDate("DATE_OF_LETTER")== null)
{ doc.add(new Field("date_of_letter","",Field.Store.YES,Field.Index.ANALYZED)); }
else {
doc.add(new Field("date_of_letter",DateTools.dateToString(rs.getDate("DATE_OF_LETTER"),
DateTools.Resolution.DAY),Field.Store.YES,Field.Index.ANALYZED));
}
if(rs.getDate("DATE_RECEIVED")== null)
{ doc.add(new Field("date_received","",Field.Store.YES,Field.Index.ANALYZED)); }
else {
doc.add(new Field("date_received",DateTools.dateToString(rs.getDate("DATE_RECEIVED"),
DateTools.Resolution.DAY),Field.Store.YES,Field.Index.ANALYZED));
}
if(rs.getString("REMARKS")== null)
{ doc.add(new Field("remarks","",Field.Store.YES,Field.Index.ANALYZED)); }
else {
doc.add(new Field("remarks",rs.getString("REMARKS"),Field.Store.YES,Field.Index.ANALYZED)); }
if(rs.getDate("DATE_DISPATCHED")== null)
{ doc.add(new Field("date_dispatched","",Field.Store.YES,Field.Index.ANALYZED)); }
else {
doc.add(new Field("date_dispatched",DateTools.dateToString(rs.getDate("DATE_DISPATCHED"),
DateTools.Resolution.MINUTE),Field.Store.YES,Field.Index.ANALYZED));
}
}
iw.addDocument(doc);
}
}
任何建议。