1 package org.apache.lucene.demo; 2 3 18 19 import java.io.File ; 20 import java.io.Reader ; 21 import java.io.FileInputStream ; 22 import java.io.BufferedReader ; 23 import java.io.InputStreamReader ; 24 25 import org.apache.lucene.document.Document; 26 import org.apache.lucene.document.Field; 27 import org.apache.lucene.document.DateField; 28 29 30 31 public class FileDocument { 32 44 public static Document Document(File f) 45 throws java.io.FileNotFoundException { 46 47 Document doc = new Document(); 49 50 doc.add(Field.Text("path", f.getPath())); 53 54 doc.add(Field.Keyword("modified", 58 DateField.timeToString(f.lastModified()))); 59 60 FileInputStream is = new FileInputStream (f); 64 Reader reader = new BufferedReader (new InputStreamReader (is)); 65 doc.add(Field.Text("contents", reader)); 66 67 return doc; 69 } 70 71 private FileDocument() {} 72 } 73 74 | Popular Tags |