001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.search.lucene2.docs; 020 021import lucee.commons.lang.StringUtil; 022import lucee.runtime.op.Caster; 023 024import org.apache.lucene.document.Document; 025 026 027/** A utility for making Lucene Documents from a File. */ 028 029public final class CustomDocument { 030 031 private static final int SUMMERY_SIZE=200; 032 033 034 /** 035 * @param title 036 * @param key 037 * @param content 038 * @param custom1 039 * @param custom2 040 * @param custom3 041 * @param custom4 042 * @return Document 043 */ 044public static Document getDocument(String title, String key, String content, 045 String urlpath,String custom1,String custom2,String custom3,String custom4) { 046 047 // make a new, empty document 048 Document doc = new Document(); 049 doc.add(FieldUtil.UnIndexed("size", Caster.toString(content.length()))); 050 051 doc.add(FieldUtil.Text("key", key)); 052 FieldUtil.setMimeType(doc, "text/plain"); 053 FieldUtil.setRaw(doc,content); 054 FieldUtil.setContent(doc, content); 055 FieldUtil.setSummary(doc, StringUtil.max(content,SUMMERY_SIZE),false); 056 057 FieldUtil.setTitle(doc, title); 058 FieldUtil.setURL(doc, urlpath); 059 FieldUtil.setCustom(doc, custom1, 1); 060 FieldUtil.setCustom(doc, custom2, 2); 061 FieldUtil.setCustom(doc, custom3, 3); 062 FieldUtil.setCustom(doc, custom4, 4); 063 return doc; 064 } 065 066 private CustomDocument() {} 067 068} 069