1 17 18 19 20 package org.apache.lenya.lucene; 21 22 import java.io.BufferedReader ; 23 import java.io.File ; 24 import java.io.FileInputStream ; 25 import java.io.InputStreamReader ; 26 import java.io.Reader ; 27 28 import org.apache.lucene.document.DateField; 29 import org.apache.lucene.document.Document; 30 import org.apache.lucene.document.Field; 31 32 35 public class FileDocument { 36 private FileDocument() { 37 } 38 39 65 public static Document Document(File f) throws java.io.FileNotFoundException { 66 Document doc = new Document(); 68 69 doc.add(Field.Text("path", f.getPath())); 72 73 doc.add(Field.Keyword("modified", DateField.timeToString(f.lastModified()))); 77 78 FileInputStream is = new FileInputStream (f); 82 Reader reader = new BufferedReader (new InputStreamReader (is)); 83 doc.add(Field.Text("contents", reader)); 84 85 return doc; 87 } 88 } 89 | Popular Tags |