如何使用lucene对html文件进行索引

 我来答
山东文汇
2016-09-03 · 我们年轻我们有活力、我们执着我们有耐心。
山东文汇
专业的软件开发服务商,网站开发、APP开发、微信小程序、商城小程序、知识付费产品。
向TA提问
展开全部
1 和普通文件一样的操作,先正则过滤掉HTML标记,只取内容。索引
2 public virtual void Add(PageViewModel model)
{
try
{
EnsureDirectoryExists();
StandardAnalyzer analyzer = new StandardAnalyzer(LUCENEVERSION);
using (IndexWriter writer = new IndexWriter(FSDirectory.Open(new DirectoryInfo(IndexPath)), analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED))
{
Document document = new Document();
document.Add(new Field("id", model.Id.ToString(), Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("content", model.Content, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("contentsummary", GetContentSummary(model), Field.Store.YES, Field.Index.NO));
document.Add(new Field("title", model.Title, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("tags", model.SpaceDelimitedTags(), Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("createdby", model.CreatedBy, Field.Store.YES, Field.Index.NOT_ANALYZED));
document.Add(new Field("createdon", model.CreatedOn.ToShortDateString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
document.Add(new Field("contentlength", model.Content.Length.ToString(), Field.Store.YES, Field.Index.NO));
writer.AddDocument(document);
writer.Optimize();
}
}
catch (Exception ex)
{
if (!ApplicationSettings.IgnoreSearchIndexErrors)
throw new SearchException(ex, "An error occured while adding page '{0}' to the search index", model.Title);
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式