HTML文档示例,使用HTML字符串代替文件
本文关键字:HTML 文件 字符串 文档 使用 | 更新日期: 2023-09-27 18:08:17
我正在做一个网络爬虫,我想使用lucene来索引,而流正在进行或完成。
我已经看到了lucene.net html库的例子很好。但是,我不想把下载保存到磁盘上。什么是我想要的,只是索引,而下载网页或索引的HTML内容字符串。
是否有任何例子,使lucence.net html索引器与内存流或字符串工作?
之类的东西?
// create writer to index
IndexWriter iw = new IndexWriter(new FileInfo("C:''example''"), new StandardAnalyzer());
// create a document to index
Document d = new Document();
// create a field that the document will contain
Field aField = new Field("test", "", Field.Store.YES, Field.Index.ANALYZED);
// add the field to the document
d.Add(aField);
// index some data (4 documents)
aField.SetValue("Example 1");
iw.AddDocument(d);
aField.SetValue("Example 2");
iw.AddDocument(d);
aField.SetValue("Example 3");
iw.AddDocument(d);
aField.SetValue("Example 4");
// a field with Store.NO can be set with a TextReader
Field notStored = new Field("test2", "", Field.Store.NO, Field.Index.ANALYZED);
notStored.SetValue(new StringReader("Example 4 - From TextReader"));
// add new field to a 4th document
d.Add(notStored);
iw.AddDocument(d);
// closing writer commits changes to disk
iw.Close();