001/* 002 * File : $Source$ 003 * Date : $Date$ 004 * Version: $Revision$ 005 * 006 * This library is part of OpenCms - 007 * the Open Source Content Management System 008 * 009 * Copyright (C) 2002 - 2009 Alkacon Software (http://www.alkacon.com) 010 * 011 * This library is free software; you can redistribute it and/or 012 * modify it under the terms of the GNU Lesser General Public 013 * License as published by the Free Software Foundation; either 014 * version 2.1 of the License, or (at your option) any later version. 015 * 016 * This library is distributed in the hope that it will be useful, 017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 * Lesser General Public License for more details. 020 * 021 * For further information about Alkacon Software, please see the 022 * company website: http://www.alkacon.com 023 * 024 * For further information about OpenCms, please see the 025 * project website: http://www.opencms.org 026 * 027 * You should have received a copy of the GNU Lesser General Public 028 * License along with this library; if not, write to the Free Software 029 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 030 */ 031 032package org.opencms.search.solr; 033 034import org.opencms.search.fields.CmsLuceneField; 035import org.opencms.search.fields.CmsSearchField; 036import org.opencms.search.fields.I_CmsSearchFieldMapping; 037 038import java.util.List; 039import java.util.Locale; 040 041/** 042 * An individual field for the Solr search index.<p> 043 * 044 * @since 8.5.0 045 */ 046public class CmsSolrField extends CmsSearchField { 047 048 /** The serial version UID. */ 049 private static final long serialVersionUID = -3920245109164517028L; 050 051 /** The fields to copy the value of this field to. */ 052 private List<String> m_copyFields; 053 054 /** The locale of this field. */ 055 private Locale m_locale; 056 057 /** The name of the field. */ 058 private String m_targetField; 059 060 /** 061 * Public constructor.<p> 062 * 063 * @param luceneField the lucene field read from the configuration. 064 */ 065 public CmsSolrField(CmsLuceneField luceneField) { 066 067 super(); 068 String name = luceneField.getName(); 069 if (null != luceneField.getType()) { 070 name = name + "_" + luceneField.getType(); 071 } 072 setName(name); 073 setDefaultValue(luceneField.getDefaultValue()); 074 075 for (I_CmsSearchFieldMapping mapping : luceneField.getMappings()) { 076 addMapping(mapping); 077 } 078 } 079 080 /** 081 * Public constructor.<p> 082 * 083 * @param targetField the target field name 084 * @param copyFields the field names to copy this field's value to 085 * @param locale the locale 086 * @param defaultValue the default value 087 */ 088 public CmsSolrField(String targetField, List<String> copyFields, Locale locale, String defaultValue) { 089 090 super(targetField, defaultValue); 091 m_targetField = targetField; 092 m_copyFields = copyFields; 093 m_locale = locale; 094 } 095 096 /** 097 * Returns the copy fields.<p> 098 * 099 * @return the copy fields.<p> 100 */ 101 public List<String> getCopyFields() { 102 103 return m_copyFields; 104 } 105 106 /** 107 * Returns the locale of this field or <code>null</code> if the field does not have a locale.<p> 108 * 109 * @return the locale of this field 110 */ 111 public Locale getLocale() { 112 113 return m_locale; 114 } 115 116 /** 117 * Returns the target field name.<p> 118 * 119 * @return the target field name 120 */ 121 public String getTargetField() { 122 123 return m_targetField; 124 } 125 126 /** 127 * Sets the copy field names.<p> 128 * 129 * @param copyFields the field name to use as copy fields 130 */ 131 public void setCopyFields(List<String> copyFields) { 132 133 m_copyFields = copyFields; 134 } 135 136 /** 137 * Sets the locale.<p> 138 * 139 * @param locale the locale to set 140 */ 141 public void setLocale(Locale locale) { 142 143 m_locale = locale; 144 } 145 146 /** 147 * Sets the target field name.<p> 148 * 149 * @param targetField the name to set 150 */ 151 public void setTargetField(String targetField) { 152 153 m_targetField = targetField; 154 } 155 156 /** 157 * @see org.opencms.search.fields.CmsSearchField#toString() 158 */ 159 @Override 160 public String toString() { 161 162 return getName() 163 + "[" 164 + " defaultValue:" 165 + getDefaultValue() 166 + " targetField:" 167 + getTargetField() 168 + " locale:" 169 + getLocale() 170 + " copyFields:" 171 + getCopyFields() 172 + " ]"; 173 } 174}