2011-09-09 5 views
0

웹 크롤러를하고 있는데 스트리밍이 진행 중이거나 완료되는 동안 색인을 생성하기 위해 lucene을 사용하고 싶습니다.Lucene.net HTML 파일 대신 html 문자열이 포함 된 문서 예제?

나는 lucene.net html 라이브러리의 예제가 좋다는 것을 알았다. 그러나 나는 디스크에 다운로드를 유지하고 싶지 않다. 내가 원하는 것은 웹을 다운로드하거나 HTML 컨텐트의 문자열 색인을 다운로드하는 동안 색인을 생성하는 것입니다.

lucence.net html 인덱서가 메모리 스트림이나 문자열로 작업하게 만드는 예제가 있습니까?

답변

0

그런 식 으로요?

 // 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();