001    /**
002     * Copyright (c) 2000-2013 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 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_ACTION_ID = "viewActionId";
168    
169            public static final String VIEW_COUNT = "viewCount";
170    
171            public Field(String name, Map<Locale, String> localizedValues) {
172                    _name = name;
173                    _localizedValues = localizedValues;
174            }
175    
176            public Field(String name, String value) {
177                    this(name, new String[] {value});
178            }
179    
180            /**
181             * @deprecated As of 6.1.0
182             */
183            public Field(String name, String value, boolean tokenized) {
184                    this(name, value);
185    
186                    setTokenized(tokenized);
187            }
188    
189            public Field(String name, String[] values) {
190                    _name = name;
191                    _values = values;
192            }
193    
194            /**
195             * @deprecated As of 6.1.0
196             */
197            public Field(String name, String[] values, boolean tokenized) {
198                    this(name, values);
199    
200                    setTokenized(tokenized);
201            }
202    
203            /**
204             * @deprecated As of 6.1.0
205             */
206            public Field(String name, String[] values, boolean tokenized, float boost) {
207                    this(name, values);
208    
209                    setBoost(boost);
210                    setTokenized(tokenized);
211            }
212    
213            public float getBoost() {
214                    return _boost;
215            }
216    
217            public Map<Locale, String> getLocalizedValues() {
218                    return _localizedValues;
219            }
220    
221            public String getName() {
222                    return _name;
223            }
224    
225            public Class<? extends Number> getNumericClass() {
226                    return _numericClass;
227            }
228    
229            public String getValue() {
230                    if (ArrayUtil.isNotEmpty(_values)) {
231                            return _values[0];
232                    }
233                    else {
234                            return null;
235                    }
236            }
237    
238            public String[] getValues() {
239                    return _values;
240            }
241    
242            public boolean isLocalized() {
243                    if (_localizedValues != null) {
244                            return true;
245                    }
246                    else {
247                            return false;
248                    }
249            }
250    
251            public boolean isNumeric() {
252                    return _numeric;
253            }
254    
255            public boolean isSortable() {
256                    return _sortable;
257            }
258    
259            public boolean isTokenized() {
260                    return _tokenized;
261            }
262    
263            public void setBoost(float boost) {
264                    _boost = boost;
265            }
266    
267            public void setName(String name) {
268                    _name = name;
269            }
270    
271            public void setNumeric(boolean numeric) {
272                    _numeric = numeric;
273            }
274    
275            public void setNumericClass(Class<? extends Number> numericClass) {
276                    _numericClass = numericClass;
277            }
278    
279            public void setSortable(boolean sortable) {
280                    _sortable = sortable;
281            }
282    
283            public void setTokenized(boolean tokenized) {
284                    _tokenized = tokenized;
285            }
286    
287            public void setValue(String value) {
288                    setValues(new String[] {value});
289            }
290    
291            public void setValues(String[] values) {
292                    _values = values;
293            }
294    
295            private float _boost = 1;
296            private Map<Locale, String> _localizedValues;
297            private String _name;
298            private boolean _numeric;
299            private Class<? extends Number> _numericClass;
300            private boolean _sortable;
301            private boolean _tokenized;
302            private String[] _values;
303    
304    }