【发布时间】:2010-07-15 15:44:23
【问题描述】:
我正在尝试使用 Lucene 为数据库中的表建立索引。我使用 Lucene 仅用于索引,不存储字段。上面提到的表格有五列(userid (PK)、description、report number、reporttype、report)。
如果 Lucene 发现命中,我打算使用用户 ID、报告编号和报告类型的组合从数据库中取回数据。
表中的一条记录可以跨越多行,例如
JQ123,SOMEDESCRIPTION,1,FIN,fin报告的内容
JQ123,AnotherDescription,2,数学,数学报告的内容
JQ123, YetAnotherDesc, 3, MATH, 另一份数学报告的内容
JD456, MoreDesc, 1, STAT, 统计报告内容..等等
一些报告类型,例如(数学)具有高度结构化的内容(XML,在最后一列中存储为字符串),将来我可能想充实一些内容 作为文档的字段。
到目前为止,我的策略是为每一行创建一个 Lucene 文档并为其编制索引。我的想法是 1. 这很容易而且看起来合乎逻辑(对我来说) 2.如果我最终从某些文档类型中提取内容并将它们放入字段中,那么只需要一个检查报告类型的 if 语句 并创建这些新字段。以下是相关代码:
public void createDocument(){
Document luceneDocument=new Document();
luceneDocument.add(new Field("userid", userID, Field.Store.NO, Field.Index.NOT_ANALYZED));
luceneDocument.add(new Field("reportnumber", reportNum, Field.Store.NO, Field.Index.NOT_ANALYZED));
luceneDocument.add(new Field("reporttype", reportType, Field.Store.NO, Field.Index.NOT_ANALYZED));
luceneDocument.add(new Field("description", description, Field.Store.NO, Field.Index.ANALYZED));
luceneDocument.add(new Field("report", report, Field.Store.NO, Field.Index.ANALYZED));
if(reporttype.equalsIgnoreCase("MATH"){
luceneDocument.add(new Field("more fields", field content, Field.Store.NO, Field.Index.ANALYZED));
}
indexwriter.add(luceneDocument)
indexwriter.close
}
1. 对同一记录使用不同的文档是否会以任何方式影响 Lucene 的搜索效率?
2. 这种方法是否会占用大量磁盘空间与 Lucene 中的每条记录有一个文档相比(我不存储任何字段)?
提前感谢您的回复,
【问题讨论】:
标签: lucene