1 17 18 19 20 package org.apache.lenya.lucene.index; 21 22 import java.io.File ; 23 24 import org.apache.lucene.document.DateField; 25 import org.apache.lucene.document.Document; 26 import org.apache.lucene.document.Field; 27 28 import org.apache.log4j.Category; 29 30 public class AbstractDocumentCreator implements DocumentCreator { 31 Category log = Category.getInstance(AbstractDocumentCreator.class); 32 33 34 public AbstractDocumentCreator() { 35 } 36 37 47 public Document getDocument(File file, File htdocsDumpDir) 48 throws Exception { 49 Document doc = new Document(); 51 52 String requestURI = file.getPath().replace(File.separatorChar, '/').substring(htdocsDumpDir.getPath() 55 .length()); 56 if (requestURI.substring(requestURI.length() - 8).equals(".pdf.txt")) { 57 requestURI = requestURI.substring(0, requestURI.length() - 4); } 59 60 doc.add(Field.UnIndexed("url", requestURI)); 61 62 if (requestURI.substring(requestURI.length() - 5).equals(".html")) { 64 doc.add(Field.UnIndexed("mime-type", "text/html")); 65 } else if (requestURI.substring(requestURI.length() - 4).equals(".txt")) { 66 doc.add(Field.UnIndexed("mime-type", "text/plain")); 67 } else if (requestURI.substring(requestURI.length() - 4).equals(".pdf")) { 68 doc.add(Field.UnIndexed("mime-type", "application/pdf")); 69 } else { 70 } 73 74 doc.add(Field.Keyword("modified", DateField.timeToString(file.lastModified()))); 78 79 String id = IndexIterator.createID(file, htdocsDumpDir); 81 log.debug(id); 82 doc.add(Field.Keyword("id", id)); 83 84 String uid = IndexIterator.createUID(file, htdocsDumpDir); 88 log.debug(uid); 89 doc.add(new Field("uid", uid, false, true, false)); 90 91 return doc; 92 } 93 } 94 | Popular Tags |