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