【发布时间】:2012-09-22 15:38:22
【问题描述】:
在搜索我想在那里显示 html 文件的关键字后,我正在使用 lucene 在客户端进行索引和搜索。那么有什么方法可以存储和访问 html 文件。实际上 html 文件存储图像和链接,它们应该在 java api 中作为普通 html 文件打开。 我正在使用以下代码进行 lucene 索引
try
{
IndexWriter indexWriter = new IndexWriter(
FSDirectory.open(indexDir),
new SimpleAnalyzer(),
true,
IndexWriter.MaxFieldLength.LIMITED);
indexWriter.setUseCompoundFile(false);
indexDirectory(indexWriter, dataDir, suffix);
Document doc = new Document();
doc.add(new Field("contents", new FileReader(f)));
doc.add(new Field("filename",f.getCanonicalPath(),
Field.Store.YES,Field.Index.ANALYZED));
indexWriter.addDocument(doc);
numIndexed = indexWriter.maxDoc();
indexWriter.optimize();
indexWriter.close();
}
catch(Exception ex)
{
}
我应该如何在客户端显示匹配搜索条件的html文件
【问题讨论】:
-
正如所写(甚至在编辑之后),您的问题难以理解。什么 HTML 文件?这些文件是如何添加到 Lucene 中的,它们存储在哪里?您是在谈论桌面(Swing)客户端还是 Web 客户端?客户是否有权访问原始文件?
-
我的建议是你退后一步,画出你的应用程序框图,然后再问你的问题。除非该代码以某种方式特定于您的问题(它看起来像是将文档添加到 Lucene 索引的通用代码),否则只需将其删除。
标签: java swing lucene swingutilities