001 package railo.runtime.search.lucene2.docs; 002 003 import org.apache.lucene.document.Document; 004 005 import railo.commons.lang.StringUtil; 006 import railo.runtime.op.Caster; 007 008 009 /** A utility for making Lucene Documents from a File. */ 010 011 public final class CustomDocument { 012 013 private static final int SUMMERY_SIZE=200; 014 015 016 /** 017 * @param title 018 * @param key 019 * @param content 020 * @param custom1 021 * @param custom2 022 * @param custom3 023 * @param custom4 024 * @return Document 025 */ 026 public static Document getDocument(String title, String key, String content, 027 String urlpath,String custom1,String custom2,String custom3,String custom4) { 028 029 // make a new, empty document 030 Document doc = new Document(); 031 doc.add(FieldUtil.UnIndexed("size", Caster.toString(content.length()))); 032 033 doc.add(FieldUtil.Text("key", key)); 034 FieldUtil.setMimeType(doc, "text/plain"); 035 FieldUtil.setRaw(doc,content); 036 FieldUtil.setContent(doc, content); 037 FieldUtil.setSummary(doc, StringUtil.max(content,SUMMERY_SIZE),false); 038 039 FieldUtil.setTitle(doc, title); 040 FieldUtil.setURL(doc, urlpath); 041 FieldUtil.setCustom(doc, custom1, 1); 042 FieldUtil.setCustom(doc, custom2, 2); 043 FieldUtil.setCustom(doc, custom3, 3); 044 FieldUtil.setCustom(doc, custom4, 4); 045 return doc; 046 } 047 048 private CustomDocument() {} 049 050 } 051