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