001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.search;
016    
017    import java.io.Serializable;
018    
019    import java.util.Locale;
020    import java.util.Map;
021    
022    /**
023     * @author Bruno Farache
024     * @author Brian Wing Shun Chan
025     * @author Allen Chiang
026     * @author Alex Wallace
027     */
028    public class Field implements Serializable {
029    
030            public static final String ASSET_CATEGORY_IDS = "assetCategoryIds";
031    
032            /**
033             * @deprecated {@link #ASSET_CATEGORY_TITLES}
034             */
035            public static final String ASSET_CATEGORY_NAMES = "assetCategoryNames";
036    
037            public static final String ASSET_CATEGORY_TITLES = "assetCategoryTitles";
038    
039            public static final String ASSET_TAG_NAMES = "assetTagNames";
040    
041            public static final String CATEGORY_ID = "categoryId";
042    
043            public static final String CLASS_NAME_ID = "classNameId";
044    
045            public static final String CLASS_PK = "classPK";
046    
047            public static final String COMMENTS = "comments";
048    
049            public static final String COMPANY_ID = "companyId";
050    
051            public static final String CONTENT = "content";
052    
053            public static final String CREATE_DATE = "createDate";
054    
055            public static final String DESCRIPTION = "description";
056    
057            public static final String ENTRY_CLASS_NAME = "entryClassName";
058    
059            public static final String ENTRY_CLASS_PK = "entryClassPK";
060    
061            public static final String FOLDER_ID = "folderId";
062    
063            public static final String GROUP_ID = "groupId";
064    
065            public static final String GROUP_ROLE_ID = "groupRoleId";
066    
067            public static final String[] KEYWORDS = {
068                    Field.ASSET_CATEGORY_TITLES, Field.ASSET_TAG_NAMES, Field.COMMENTS,
069                    Field.CONTENT, Field.DESCRIPTION, Field.PROPERTIES, Field.TITLE,
070                    Field.URL, Field.USER_NAME
071            };
072    
073            /**
074             * @deprecated {@link #MODIFIED_DATE}
075             */
076            public static final String MODIFIED = "modified";
077    
078            public static final String MODIFIED_DATE = "modified";
079    
080            public static final String NAME = "name";
081    
082            public static final String NODE_ID = "nodeId";
083    
084            public static final String ORGANIZATION_ID = "organizationId";
085    
086            public static final String PORTLET_ID = "portletId";
087    
088            public static final String PROPERTIES = "properties";
089    
090            public static final String ROLE_ID = "roleId";
091    
092            public static final String ROOT_ENTRY_CLASS_PK = "rootEntryClassPK";
093    
094            public static final String SCOPE_GROUP_ID = "scopeGroupId";
095    
096            public static final String SNIPPET = "snippet";
097    
098            public static final String STAGING_GROUP = "stagingGroup";
099    
100            public static final String STATUS = "status";
101    
102            public static final String TITLE = "title";
103    
104            public static final String TYPE = "type";
105    
106            public static final String UID = "uid";
107    
108            public static final String[] UNSCORED_FIELD_NAMES = {
109                    Field.ASSET_CATEGORY_IDS, Field.COMPANY_ID, Field.ENTRY_CLASS_NAME,
110                    Field.ENTRY_CLASS_PK, Field.FOLDER_ID, Field.GROUP_ID,
111                    Field.GROUP_ROLE_ID, Field.PORTLET_ID, Field.ROLE_ID,
112                    Field.SCOPE_GROUP_ID, Field.USER_ID
113            };
114    
115            public static final String URL = "url";
116    
117            public static final String USER_ID = "userId";
118    
119            public static final String USER_NAME = "userName";
120    
121            public static final String VERSION = "version";
122    
123            public Field(String name, Map<Locale, String> localizedValues) {
124                    _name = name;
125                    _localizedValues = localizedValues;
126            }
127    
128            public Field(String name, String value) {
129                    this(name, new String[] {value});
130            }
131    
132            public Field(String name, String[] values) {
133                    _name = name;
134                    _values = values;
135            }
136    
137            /**
138             * @deprecated
139             */
140            public Field(String name, String value, boolean tokenized) {
141                    this(name, value);
142    
143                    setTokenized(tokenized);
144            }
145    
146            /**
147             * @deprecated
148             */
149            public Field(String name, String[] values, boolean tokenized) {
150                    this(name, values);
151    
152                    setTokenized(tokenized);
153            }
154    
155            /**
156             * @deprecated
157             */
158            public Field(String name, String[] values, boolean tokenized, float boost) {
159                    this(name, values);
160    
161                    setBoost(boost);
162                    setTokenized(tokenized);
163            }
164    
165            public float getBoost() {
166                    return _boost;
167            }
168    
169            public Map<Locale, String> getLocalizedValues() {
170                    return _localizedValues;
171            }
172    
173            public String getName() {
174                    return _name;
175            }
176    
177            public String getValue() {
178                    if ((_values != null) && (_values.length > 0)) {
179                            return _values[0];
180                    }
181                    else {
182                            return null;
183                    }
184            }
185    
186            public String[] getValues() {
187                    return _values;
188            }
189    
190            public boolean isLocalized() {
191                    if (_localizedValues != null) {
192                            return true;
193                    }
194                    else {
195                            return false;
196                    }
197            }
198    
199            public boolean isNumeric() {
200                    return _numeric;
201            }
202    
203            public boolean isTokenized() {
204                    return _tokenized;
205            }
206    
207            public void setBoost(float boost) {
208                    _boost = boost;
209            }
210    
211            public void setName(String name) {
212                    _name = name;
213            }
214    
215            public void setNumeric(boolean numeric) {
216                    _numeric = numeric;
217            }
218    
219            public void setTokenized(boolean tokenized) {
220                    _tokenized = tokenized;
221            }
222    
223            public void setValue(String value) {
224                    setValues(new String[] {value});
225            }
226    
227            public void setValues(String[] values) {
228                    _values = values;
229            }
230    
231            private float _boost = 1;
232            private Map<Locale, String> _localizedValues;
233            private String _name;
234            private boolean _numeric;
235            private boolean _tokenized;
236            private String[] _values;
237    
238    }