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;
022
023import org.apache.lucene.document.Document;
024import org.apache.lucene.document.Field;
025
026public class FieldUtil {
027
028        public static Field UnIndexed(String name, String value) {
029                return new Field(name,value,Field.Store.YES,Field.Index.NO);
030        }
031
032        public static Field Text(String name, String value) {//print.out("text:"+name);
033                return new Field(name,value,Field.Store.YES,Field.Index.ANALYZED);
034        }
035
036        public static Field Text(String name, String value,boolean store) {
037                return new Field(name,value,store?Field.Store.YES:Field.Store.NO,Field.Index.ANALYZED);
038        }
039
040        public static void setTitle(Document doc, String title) {
041                if(!StringUtil.isEmpty(title))          doc.add(Text("title", title));
042        }
043
044        public static void setSummary(Document doc, String summary,boolean index) {
045                if(!StringUtil.isEmpty(summary))        doc.add(index?Text("summary",summary):UnIndexed("summary",summary));
046        }
047
048        public static void setKeywords(Document doc, String keywords) {
049                if(!StringUtil.isEmpty(keywords))       doc.add(Text("keywords", keywords));
050        }
051
052        public static void setAuthor(Document doc, String author) {
053                if(!StringUtil.isEmpty(author))         doc.add(Text("author", author));
054        }
055
056        public static void setURL(Document doc, String urlpath) {
057                if(!StringUtil.isEmpty(urlpath))                doc.add(Text("url", urlpath));
058        }
059        public static void setCustom(Document doc, String custom, int index) {
060                if(!StringUtil.isEmpty(custom))         doc.add(Text("custom"+index, custom));
061        }
062
063        public static void setContent(Document doc, String content) {
064                if(!StringUtil.isEmpty(content))        doc.add(Text("contents", content));
065        }
066
067        public static void setRaw(Document doc, String raw) {
068                //doc.add(new Field("raw",raw,Field.Store.YES,Field.Index.NO));
069        }
070
071        public static void setMimeType(Document doc, String mimeType) {
072                if(!StringUtil.isEmpty(mimeType))       doc.add(FieldUtil.UnIndexed("mime-type", mimeType));
073        }
074
075        
076}