001
014
015 package com.liferay.portal.kernel.search;
016
017 import com.liferay.portal.kernel.dao.orm.QueryUtil;
018 import com.liferay.portal.kernel.search.facet.Facet;
019 import com.liferay.portal.kernel.util.ArrayUtil;
020 import com.liferay.portal.kernel.util.LocaleUtil;
021 import com.liferay.portal.kernel.util.Validator;
022 import com.liferay.portal.model.Layout;
023
024 import java.io.Serializable;
025
026 import java.util.HashMap;
027 import java.util.List;
028 import java.util.Locale;
029 import java.util.Map;
030 import java.util.TimeZone;
031 import java.util.concurrent.ConcurrentHashMap;
032
033
037 public class SearchContext implements Serializable {
038
039 public void addFacet(Facet facet) {
040 if (facet == null) {
041 return;
042 }
043
044 _facets.put(facet.getFieldName(), facet);
045 }
046
047 public long[] getAssetCategoryIds() {
048 return _assetCategoryIds;
049 }
050
051 public String[] getAssetTagNames() {
052 return _assetTagNames;
053 }
054
055 public Serializable getAttribute(String name) {
056 if (_attributes == null) {
057 return null;
058 }
059
060 return _attributes.get(name);
061 }
062
063 public Map<String, Serializable> getAttributes() {
064 if (_attributes == null) {
065 _attributes = new HashMap<String, Serializable>();
066 }
067
068 return _attributes;
069 }
070
071 public BooleanClause[] getBooleanClauses() {
072 return _booleanClauses;
073 }
074
075 public long[] getCategoryIds() {
076 return _categoryIds;
077 }
078
079 public long[] getClassTypeIds() {
080 return _classTypeIds;
081 }
082
083 public long getCompanyId() {
084 return _companyId;
085 }
086
087 public int getEnd() {
088 return _end;
089 }
090
091 public String[] getEntryClassNames() {
092 if (_entryClassNames == null) {
093 _entryClassNames = new String[0];
094 }
095
096 return _entryClassNames;
097 }
098
099 public Facet getFacet(String fieldName) {
100 return _facets.get(fieldName);
101 }
102
103 public Map<String, Facet> getFacets() {
104 return _facets;
105 }
106
107 public long[] getFolderIds() {
108 return _folderIds;
109 }
110
111 public long[] getGroupIds() {
112 return _groupIds;
113 }
114
115 public String getKeywords() {
116 return _keywords;
117 }
118
119 public String getLanguageId() {
120 return LocaleUtil.toLanguageId(_locale);
121 }
122
123 public Layout getLayout() {
124 return _layout;
125 }
126
127 public Locale getLocale() {
128 return _locale;
129 }
130
131 public long[] getNodeIds() {
132 return _nodeIds;
133 }
134
135 public long getOwnerUserId() {
136 return _ownerUserId;
137 }
138
139 public String[] getPortletIds() {
140 return _portletIds;
141 }
142
143 public QueryConfig getQueryConfig() {
144 if (_queryConfig == null) {
145 _queryConfig = new QueryConfig();
146 }
147
148 return _queryConfig;
149 }
150
151 public float getScoresThreshold() {
152 return _scoresThreshold;
153 }
154
155 public String getSearchEngineId() {
156 if (Validator.isNull(_searchEngineId)) {
157 return SearchEngineUtil.getDefaultSearchEngineId();
158 }
159
160 return _searchEngineId;
161 }
162
163 public Sort[] getSorts() {
164 return _sorts;
165 }
166
167 public int getStart() {
168 return _start;
169 }
170
171 public TimeZone getTimeZone() {
172 return _timeZone;
173 }
174
175 public long getUserId() {
176 return _userId;
177 }
178
179 public boolean hasOverridenKeywords() {
180 return Validator.isNull(_originalKeywords);
181 }
182
183 public boolean isAndSearch() {
184 return _andSearch;
185 }
186
187 public boolean isIncludeAttachments() {
188 return _includeAttachments;
189 }
190
191 public boolean isIncludeDiscussions() {
192 return _includeDiscussions;
193 }
194
195 public boolean isIncludeLiveGroups() {
196 return _includeLiveGroups;
197 }
198
199 public boolean isIncludeStagingGroups() {
200 return _includeStagingGroups;
201 }
202
203 public boolean isLike() {
204 return _like;
205 }
206
207 public boolean isScopeStrict() {
208 return _scopeStrict;
209 }
210
211 public void overrideKeywords(String keywords) {
212 _originalKeywords = _keywords;
213
214 _keywords = keywords;
215 }
216
217 public void setAndSearch(boolean andSearch) {
218 _andSearch = andSearch;
219 }
220
221 public void setAssetCategoryIds(long[] assetCategoryIds) {
222 _assetCategoryIds = assetCategoryIds;
223 }
224
225 public void setAssetTagNames(String[] assetTagNames) {
226 _assetTagNames = assetTagNames;
227 }
228
229 public void setAttribute(String name, Serializable value) {
230 if (_attributes == null) {
231 _attributes = new HashMap<String, Serializable>();
232 }
233
234 _attributes.put(name, value);
235 }
236
237 public void setAttributes(Map<String, Serializable> attributes) {
238 _attributes = attributes;
239 }
240
241 public void setBooleanClauses(BooleanClause[] booleanClauses) {
242 _booleanClauses = booleanClauses;
243 }
244
245 public void setCategoryIds(long[] categoryIds) {
246 _categoryIds = categoryIds;
247 }
248
249 public void setClassTypeIds(long[] classTypeIds) {
250 _classTypeIds = classTypeIds;
251 }
252
253 public void setCompanyId(long companyId) {
254 _companyId = companyId;
255 }
256
257 public void setEnd(int end) {
258 _end = end;
259 }
260
261 public void setEntryClassNames(String[] entryClassNames) {
262 _entryClassNames = entryClassNames;
263 }
264
265 public void setFacets(List<Facet> facets) {
266 for (Facet facet : facets) {
267 _facets.put(facet.getFieldName(), facet);
268 }
269 }
270
271 public void setFolderIds(List<Long> folderIds) {
272 _folderIds = ArrayUtil.toArray(
273 folderIds.toArray(new Long[folderIds.size()]));
274 }
275
276 public void setFolderIds(long[] folderIds) {
277 _folderIds = folderIds;
278 }
279
280 public void setGroupIds(long[] groupIds) {
281 _groupIds = groupIds;
282 }
283
284 public void setIncludeAttachments(boolean includeAttachments) {
285 _includeAttachments = includeAttachments;
286 }
287
288 public void setIncludeDiscussions(boolean includeDiscussions) {
289 _includeDiscussions = includeDiscussions;
290 }
291
292 public void setIncludeLiveGroups(boolean includeLiveGroups) {
293 _includeLiveGroups = includeLiveGroups;
294 }
295
296 public void setIncludeStagingGroups(boolean includeStagingGroups) {
297 _includeStagingGroups = includeStagingGroups;
298 }
299
300 public void setKeywords(String keywords) {
301 _keywords = keywords;
302 }
303
304 public void setLayout(Layout layout) {
305 _layout = layout;
306 }
307
308 public void setLike(boolean like) {
309 _like = like;
310 }
311
312 public void setLocale(Locale locale) {
313 if (locale != null) {
314 _locale = locale;
315 }
316 }
317
318 public void setNodeIds(long[] nodeIds) {
319 _nodeIds = nodeIds;
320 }
321
322 public void setOwnerUserId(long ownerUserId) {
323 _ownerUserId = ownerUserId;
324 }
325
326 public void setPortletIds(String[] portletIds) {
327 _portletIds = portletIds;
328 }
329
330 public void setQueryConfig(QueryConfig queryConfig) {
331 _queryConfig = queryConfig;
332 }
333
334 public void setScopeStrict(boolean scopeStrict) {
335 _scopeStrict = scopeStrict;
336 }
337
338 public void setScoresThreshold(float scoresThreshold) {
339 _scoresThreshold = scoresThreshold;
340 }
341
342 public void setSearchEngineId(String searchEngineId) {
343 if (_searchEngineId == null) {
344 _searchEngineId = searchEngineId;
345 }
346 }
347
348 public void setSorts(Sort... sorts) {
349 _sorts = sorts;
350 }
351
352 public void setStart(int start) {
353 _start = start;
354 }
355
356 public void setTimeZone(TimeZone timeZone) {
357 _timeZone = timeZone;
358 }
359
360 public void setUserId(long userId) {
361 _userId = userId;
362 }
363
364 private boolean _andSearch;
365 private long[] _assetCategoryIds;
366 private String[] _assetTagNames;
367 private Map<String, Serializable> _attributes;
368 private BooleanClause[] _booleanClauses;
369 private long[] _categoryIds;
370 private long[] _classTypeIds;
371 private long _companyId;
372 private int _end = QueryUtil.ALL_POS;
373 private String[] _entryClassNames;
374 private Map<String, Facet> _facets = new ConcurrentHashMap<String, Facet>();
375 private long[] _folderIds;
376 private long[] _groupIds;
377 private boolean _includeAttachments;
378 private boolean _includeDiscussions;
379 private boolean _includeLiveGroups = true;
380 private boolean _includeStagingGroups = true;
381 private String _keywords;
382 private Layout _layout;
383 private boolean _like;
384 private Locale _locale = LocaleUtil.getMostRelevantLocale();
385 private long[] _nodeIds;
386 private String _originalKeywords;
387 private long _ownerUserId;
388 private String[] _portletIds;
389 private QueryConfig _queryConfig;
390 private boolean _scopeStrict = true;
391 private float _scoresThreshold;
392 private String _searchEngineId;
393 private Sort[] _sorts;
394 private int _start = QueryUtil.ALL_POS;
395 private TimeZone _timeZone;
396 private long _userId;
397
398 }