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