【发布时间】:2012-09-15 10:59:18
【问题描述】:
您好,我是 lucene 新手,我使用 lucene 创建了索引。我将两个字段文件名和文件内容添加到 lucene 索引。 但是当我从索引中搜索时,我能够得到查询词的出现和包含查询词的文件名。我无法查看已为其创建索引的文件的内容 有人可以帮忙吗 提前谢谢
Directory directory = FSDirectory.open(indexDir);
IndexSearcher searcher = new IndexSearcher(directory,true);
QueryParser parser =
new QueryParser(Version.LUCENE_30,"contents", new SimpleAnalyzer());
Query query = parser.parse(queryStr);
query.setBoost((float)1.5);
TopDocs topDocs = searcher.search(query, maxHits);
ScoreDoc[] hits = topDocs.scoreDocs;
arr= new String[hits.length];
for ( i = 0; i <hits.length; i++) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
arr[i]=d.get("filename");
}
我正在使用此代码来读取索引。
【问题讨论】: