001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.search;
016    
017    import com.liferay.portal.kernel.util.ArrayUtil;
018    
019    import java.io.Serializable;
020    
021    import java.util.Locale;
022    import java.util.Map;
023    
024    /**
025     * @author Bruno Farache
026     * @author Brian Wing Shun Chan
027     * @author Allen Chiang
028     * @author Alex Wallace
029     */
030    public class Field implements Serializable {
031    
032            public static final String ASSET_CATEGORY_ID = "assetCategoryId";
033    
034            public static final String ASSET_CATEGORY_IDS = "assetCategoryIds";
035    
036            /**
037             * @deprecated As of 6.2.0, replaced by {@link #ASSET_CATEGORY_TITLES}
038             */
039            public static final String ASSET_CATEGORY_NAMES = "assetCategoryNames";
040    
041            public static final String ASSET_CATEGORY_TITLE = "assetCategoryTitle";
042    
043            public static final String ASSET_CATEGORY_TITLES = "assetCategoryTitles";
044    
045            public static final String ASSET_TAG_IDS = "assetTagIds";
046    
047            public static final String ASSET_TAG_NAMES = "assetTagNames";
048    
049            public static final String ASSET_VOCABULARY_ID = "assetVocabularyId";
050    
051            public static final String ASSET_VOCABULARY_IDS = "assetVocabularyIds";
052    
053            public static final String CATEGORY_ID = "categoryId";
054    
055            public static final String CLASS_NAME_ID = "classNameId";
056    
057            public static final String CLASS_PK = "classPK";
058    
059            public static final String CLASS_TYPE_ID = "classTypeId";
060    
061            public static final String COMMENTS = "comments";
062    
063            public static final String COMPANY_ID = "companyId";
064    
065            public static final String CONTENT = "content";
066    
067            public static final String CREATE_DATE = "createDate";
068    
069            public static final String DESCRIPTION = "description";
070    
071            public static final String ENTRY_CLASS_NAME = "entryClassName";
072    
073            public static final String ENTRY_CLASS_PK = "entryClassPK";
074    
075            public static final String EXPIRATION_DATE = "expirationDate";
076    
077            public static final String FOLDER_ID = "folderId";
078    
079            public static final String GROUP_ID = "groupId";
080    
081            public static final String GROUP_ROLE_ID = "groupRoleId";
082    
083            public static final String HIDDEN = "hidden";
084    
085            public static final String KEYWORD_SEARCH = "keywordSearch";
086    
087            public static final String[] KEYWORDS = {
088                    Field.ASSET_CATEGORY_TITLES, Field.ASSET_TAG_NAMES, Field.COMMENTS,
089                    Field.CONTENT, Field.DESCRIPTION, Field.PROPERTIES, Field.TITLE,
090                    Field.URL, Field.USER_NAME
091            };
092    
093            public static final String LANGUAGE_ID = "languageId";
094    
095            public static final String LAYOUT_UUID = "layoutUuid";
096    
097            /**
098             * @deprecated As of 6.1.0, replaced by {@link #MODIFIED_DATE}
099             */
100            public static final String MODIFIED = "modified";
101    
102            public static final String MODIFIED_DATE = "modified";
103    
104            public static final String NAME = "name";
105    
106            public static final String NODE_ID = "nodeId";
107    
108            public static final String ORGANIZATION_ID = "organizationId";
109    
110            public static final String PORTLET_ID = "portletId";
111    
112            public static final String PRIORITY = "priority";
113    
114            public static final String PROPERTIES = "properties";
115    
116            public static final String PUBLISH_DATE = "publishDate";
117    
118            public static final String RATINGS = "ratings";
119    
120            public static final String RELATED_ENTRY = "relatedEntry";
121    
122            public static final String REMOVED_BY_USER_NAME = "removedByUserName";
123    
124            public static final String REMOVED_DATE = "removedDate";
125    
126            public static final String ROLE_ID = "roleId";
127    
128            public static final String ROOT_ENTRY_CLASS_NAME = "rootEntryClassName";
129    
130            public static final String ROOT_ENTRY_CLASS_PK = "rootEntryClassPK";
131    
132            public static final String SCOPE_GROUP_ID = "scopeGroupId";
133    
134            public static final String SNIPPET = "snippet";
135    
136            public static final String SPELL_CHECK_WORD = "spellCheckWord";
137    
138            public static final String STAGING_GROUP = "stagingGroup";
139    
140            public static final String STATUS = "status";
141    
142            public static final String TITLE = "title";
143    
144            public static final String TREE_PATH = "treePath";
145    
146            public static final String TYPE = "type";
147    
148            public static final String UID = "uid";
149    
150            public static final String[] UNSCORED_FIELD_NAMES = {
151                    Field.ASSET_CATEGORY_IDS, Field.COMPANY_ID, Field.ENTRY_CLASS_NAME,
152                    Field.ENTRY_CLASS_PK, Field.FOLDER_ID, Field.GROUP_ID,
153                    Field.GROUP_ROLE_ID, Field.PORTLET_ID, Field.ROLE_ID,
154                    Field.SCOPE_GROUP_ID, Field.USER_ID
155            };
156    
157            public static final String URL = "url";
158    
159            public static final String USER_GROUP_ID = "userGroupId";
160    
161            public static final String USER_ID = "userId";
162    
163            public static final String USER_NAME = "userName";
164    
165            public static final String VERSION = "version";
166    
167            public static final String VIEW_COUNT = "viewCount";
168    
169            public Field(String name, Map<Locale, String> localizedValues) {
170                    _name = name;
171                    _localizedValues = localizedValues;
172            }
173    
174            public Field(String name, String value) {
175                    this(name, new String[] {value});
176            }
177    
178            /**
179             * @deprecated As of 6.1.0
180             */
181            public Field(String name, String value, boolean tokenized) {
182                    this(name, value);
183    
184                    setTokenized(tokenized);
185            }
186    
187            public Field(String name, String[] values) {
188                    _name = name;
189                    _values = values;
190            }
191    
192            /**
193             * @deprecated As of 6.1.0
194             */
195            public Field(String name, String[] values, boolean tokenized) {
196                    this(name, values);
197    
198                    setTokenized(tokenized);
199            }
200    
201            /**
202             * @deprecated As of 6.1.0
203             */
204            public Field(String name, String[] values, boolean tokenized, float boost) {
205                    this(name, values);
206    
207                    setBoost(boost);
208                    setTokenized(tokenized);
209            }
210    
211            public float getBoost() {
212                    return _boost;
213            }
214    
215            public Map<Locale, String> getLocalizedValues() {
216                    return _localizedValues;
217            }
218    
219            public String getName() {
220                    return _name;
221            }
222    
223            public Class<? extends Number> getNumericClass() {
224                    return _numericClass;
225            }
226    
227            public String getValue() {
228                    if (ArrayUtil.isNotEmpty(_values)) {
229                            return _values[0];
230                    }
231                    else {
232                            return null;
233                    }
234            }
235    
236            public String[] getValues() {
237                    return _values;
238            }
239    
240            public boolean isLocalized() {
241                    if (_localizedValues != null) {
242                            return true;
243                    }
244                    else {
245                            return false;
246                    }
247            }
248    
249            public boolean isNumeric() {
250                    return _numeric;
251            }
252    
253            public boolean isSortable() {
254                    return _sortable;
255            }
256    
257            public boolean isTokenized() {
258                    return _tokenized;
259            }
260    
261            public void setBoost(float boost) {
262                    _boost = boost;
263            }
264    
265            public void setName(String name) {
266                    _name = name;
267            }
268    
269            public void setNumeric(boolean numeric) {
270                    _numeric = numeric;
271            }
272    
273            public void setNumericClass(Class<? extends Number> numericClass) {
274                    _numericClass = numericClass;
275            }
276    
277            public void setSortable(boolean sortable) {
278                    _sortable = sortable;
279            }
280    
281            public void setTokenized(boolean tokenized) {
282                    _tokenized = tokenized;
283            }
284    
285            public void setValue(String value) {
286                    setValues(new String[] {value});
287            }
288    
289            public void setValues(String[] values) {
290                    _values = values;
291            }
292    
293            private float _boost = 1;
294            private Map<Locale, String> _localizedValues;
295            private String _name;
296            private boolean _numeric;
297            private Class<? extends Number> _numericClass;
298            private boolean _sortable;
299            private boolean _tokenized;
300            private String[] _values;
301    
302    }