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_IDS = "assetCategoryIds";
033    
034            /**
035             * @deprecated As of 6.2.0, replaced by {@link #ASSET_CATEGORY_TITLES}
036             */
037            public static final String ASSET_CATEGORY_NAMES = "assetCategoryNames";
038    
039            public static final String ASSET_CATEGORY_TITLES = "assetCategoryTitles";
040    
041            public static final String ASSET_TAG_IDS = "assetTagIds";
042    
043            public static final String ASSET_TAG_NAMES = "assetTagNames";
044    
045            public static final String CATEGORY_ID = "categoryId";
046    
047            public static final String CLASS_NAME_ID = "classNameId";
048    
049            public static final String CLASS_PK = "classPK";
050    
051            public static final String CLASS_TYPE_ID = "classTypeId";
052    
053            public static final String COMMENTS = "comments";
054    
055            public static final String COMPANY_ID = "companyId";
056    
057            public static final String CONTENT = "content";
058    
059            public static final String CREATE_DATE = "createDate";
060    
061            public static final String DESCRIPTION = "description";
062    
063            public static final String ENTRY_CLASS_NAME = "entryClassName";
064    
065            public static final String ENTRY_CLASS_PK = "entryClassPK";
066    
067            public static final String EXPIRATION_DATE = "expirationDate";
068    
069            public static final String FOLDER_ID = "folderId";
070    
071            public static final String GROUP_ID = "groupId";
072    
073            public static final String GROUP_ROLE_ID = "groupRoleId";
074    
075            public static final String HIDDEN = "hidden";
076    
077            public static final String KEYWORD_SEARCH = "keywordSearch";
078    
079            public static final String[] KEYWORDS = {
080                    Field.ASSET_CATEGORY_TITLES, Field.ASSET_TAG_NAMES, Field.COMMENTS,
081                    Field.CONTENT, Field.DESCRIPTION, Field.PROPERTIES, Field.TITLE,
082                    Field.URL, Field.USER_NAME
083            };
084    
085            public static final String LANGUAGE_ID = "languageId";
086    
087            public static final String LAYOUT_UUID = "layoutUuid";
088    
089            /**
090             * @deprecated As of 6.1.0, replaced by {@link #MODIFIED_DATE}
091             */
092            public static final String MODIFIED = "modified";
093    
094            public static final String MODIFIED_DATE = "modified";
095    
096            public static final String NAME = "name";
097    
098            public static final String NODE_ID = "nodeId";
099    
100            public static final String ORGANIZATION_ID = "organizationId";
101    
102            public static final String PORTLET_ID = "portletId";
103    
104            public static final String PRIORITY = "priority";
105    
106            public static final String PROPERTIES = "properties";
107    
108            public static final String PUBLISH_DATE = "publishDate";
109    
110            public static final String RATINGS = "ratings";
111    
112            public static final String RELATED_ENTRY = "relatedEntry";
113    
114            public static final String REMOVED_BY_USER_NAME = "removedByUserName";
115    
116            public static final String REMOVED_DATE = "removedDate";
117    
118            public static final String ROLE_ID = "roleId";
119    
120            public static final String ROOT_ENTRY_CLASS_NAME = "rootEntryClassName";
121    
122            public static final String ROOT_ENTRY_CLASS_PK = "rootEntryClassPK";
123    
124            public static final String SCOPE_GROUP_ID = "scopeGroupId";
125    
126            public static final String SNIPPET = "snippet";
127    
128            public static final String SPELL_CHECK_WORD = "spellCheckWord";
129    
130            public static final String STAGING_GROUP = "stagingGroup";
131    
132            public static final String STATUS = "status";
133    
134            public static final String TITLE = "title";
135    
136            public static final String TYPE = "type";
137    
138            public static final String UID = "uid";
139    
140            public static final String[] UNSCORED_FIELD_NAMES = {
141                    Field.ASSET_CATEGORY_IDS, Field.COMPANY_ID, Field.ENTRY_CLASS_NAME,
142                    Field.ENTRY_CLASS_PK, Field.FOLDER_ID, Field.GROUP_ID,
143                    Field.GROUP_ROLE_ID, Field.PORTLET_ID, Field.ROLE_ID,
144                    Field.SCOPE_GROUP_ID, Field.USER_ID
145            };
146    
147            public static final String URL = "url";
148    
149            public static final String USER_GROUP_ID = "userGroupId";
150    
151            public static final String USER_ID = "userId";
152    
153            public static final String USER_NAME = "userName";
154    
155            public static final String VERSION = "version";
156    
157            public static final String VIEW_COUNT = "viewCount";
158    
159            public Field(String name, Map<Locale, String> localizedValues) {
160                    _name = name;
161                    _localizedValues = localizedValues;
162            }
163    
164            public Field(String name, String value) {
165                    this(name, new String[] {value});
166            }
167    
168            /**
169             * @deprecated As of 6.1.0
170             */
171            public Field(String name, String value, boolean tokenized) {
172                    this(name, value);
173    
174                    setTokenized(tokenized);
175            }
176    
177            public Field(String name, String[] values) {
178                    _name = name;
179                    _values = values;
180            }
181    
182            /**
183             * @deprecated As of 6.1.0
184             */
185            public Field(String name, String[] values, boolean tokenized) {
186                    this(name, values);
187    
188                    setTokenized(tokenized);
189            }
190    
191            /**
192             * @deprecated As of 6.1.0
193             */
194            public Field(String name, String[] values, boolean tokenized, float boost) {
195                    this(name, values);
196    
197                    setBoost(boost);
198                    setTokenized(tokenized);
199            }
200    
201            public float getBoost() {
202                    return _boost;
203            }
204    
205            public Map<Locale, String> getLocalizedValues() {
206                    return _localizedValues;
207            }
208    
209            public String getName() {
210                    return _name;
211            }
212    
213            public Class<? extends Number> getNumericClass() {
214                    return _numericClass;
215            }
216    
217            public String getValue() {
218                    if (ArrayUtil.isNotEmpty(_values)) {
219                            return _values[0];
220                    }
221                    else {
222                            return null;
223                    }
224            }
225    
226            public String[] getValues() {
227                    return _values;
228            }
229    
230            public boolean isLocalized() {
231                    if (_localizedValues != null) {
232                            return true;
233                    }
234                    else {
235                            return false;
236                    }
237            }
238    
239            public boolean isNumeric() {
240                    return _numeric;
241            }
242    
243            public boolean isTokenized() {
244                    return _tokenized;
245            }
246    
247            public void setBoost(float boost) {
248                    _boost = boost;
249            }
250    
251            public void setName(String name) {
252                    _name = name;
253            }
254    
255            public void setNumeric(boolean numeric) {
256                    _numeric = numeric;
257            }
258    
259            public void setNumericClass(Class<? extends Number> numericClass) {
260                    _numericClass = numericClass;
261            }
262    
263            public void setTokenized(boolean tokenized) {
264                    _tokenized = tokenized;
265            }
266    
267            public void setValue(String value) {
268                    setValues(new String[] {value});
269            }
270    
271            public void setValues(String[] values) {
272                    _values = values;
273            }
274    
275            private float _boost = 1;
276            private Map<Locale, String> _localizedValues;
277            private String _name;
278            private boolean _numeric;
279            private Class<? extends Number> _numericClass;
280            private boolean _tokenized;
281            private String[] _values;
282    
283    }