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 isCommitImmediately() {
188 return _commitImmediately;
189 }
190
191 public boolean isIncludeAttachments() {
192 return _includeAttachments;
193 }
194
195 public boolean isIncludeDiscussions() {
196 return _includeDiscussions;
197 }
198
199 public boolean isIncludeLiveGroups() {
200 return _includeLiveGroups;
201 }
202
203 public boolean isIncludeStagingGroups() {
204 return _includeStagingGroups;
205 }
206
207 public boolean isLike() {
208 return _like;
209 }
210
211 public boolean isScopeStrict() {
212 return _scopeStrict;
213 }
214
215 public void overrideKeywords(String keywords) {
216 _originalKeywords = _keywords;
217
218 _keywords = keywords;
219 }
220
221 public void setAndSearch(boolean andSearch) {
222 _andSearch = andSearch;
223 }
224
225 public void setAssetCategoryIds(long[] assetCategoryIds) {
226 _assetCategoryIds = assetCategoryIds;
227 }
228
229 public void setAssetTagNames(String[] assetTagNames) {
230 _assetTagNames = assetTagNames;
231 }
232
233 public void setAttribute(String name, Serializable value) {
234 if (_attributes == null) {
235 _attributes = new HashMap<String, Serializable>();
236 }
237
238 _attributes.put(name, value);
239 }
240
241 public void setAttributes(Map<String, Serializable> attributes) {
242 _attributes = attributes;
243 }
244
245 public void setBooleanClauses(BooleanClause[] booleanClauses) {
246 _booleanClauses = booleanClauses;
247 }
248
249 public void setCategoryIds(long[] categoryIds) {
250 _categoryIds = categoryIds;
251 }
252
253 public void setClassTypeIds(long[] classTypeIds) {
254 _classTypeIds = classTypeIds;
255 }
256
257 public void setCommitImmediately(boolean commitImmediately) {
258 _commitImmediately = commitImmediately;
259 }
260
261 public void setCompanyId(long companyId) {
262 _companyId = companyId;
263 }
264
265 public void setEnd(int end) {
266 _end = end;
267 }
268
269 public void setEntryClassNames(String[] entryClassNames) {
270 _entryClassNames = entryClassNames;
271 }
272
273 public void setFacets(List<Facet> facets) {
274 for (Facet facet : facets) {
275 _facets.put(facet.getFieldName(), facet);
276 }
277 }
278
279 public void setFolderIds(List<Long> folderIds) {
280 _folderIds = ArrayUtil.toArray(
281 folderIds.toArray(new Long[folderIds.size()]));
282 }
283
284 public void setFolderIds(long[] folderIds) {
285 _folderIds = folderIds;
286 }
287
288 public void setGroupIds(long[] groupIds) {
289 _groupIds = groupIds;
290 }
291
292 public void setIncludeAttachments(boolean includeAttachments) {
293 _includeAttachments = includeAttachments;
294 }
295
296 public void setIncludeDiscussions(boolean includeDiscussions) {
297 _includeDiscussions = includeDiscussions;
298 }
299
300 public void setIncludeLiveGroups(boolean includeLiveGroups) {
301 _includeLiveGroups = includeLiveGroups;
302 }
303
304 public void setIncludeStagingGroups(boolean includeStagingGroups) {
305 _includeStagingGroups = includeStagingGroups;
306 }
307
308 public void setKeywords(String keywords) {
309 _keywords = keywords;
310 }
311
312 public void setLayout(Layout layout) {
313 _layout = layout;
314 }
315
316 public void setLike(boolean like) {
317 _like = like;
318 }
319
320 public void setLocale(Locale locale) {
321 if (locale != null) {
322 _locale = locale;
323 }
324 }
325
326 public void setNodeIds(long[] nodeIds) {
327 _nodeIds = nodeIds;
328 }
329
330 public void setOwnerUserId(long ownerUserId) {
331 _ownerUserId = ownerUserId;
332 }
333
334 public void setPortletIds(String[] portletIds) {
335 _portletIds = portletIds;
336 }
337
338 public void setQueryConfig(QueryConfig queryConfig) {
339 _queryConfig = queryConfig;
340 }
341
342 public void setScopeStrict(boolean scopeStrict) {
343 _scopeStrict = scopeStrict;
344 }
345
346 public void setScoresThreshold(float scoresThreshold) {
347 _scoresThreshold = scoresThreshold;
348 }
349
350 public void setSearchEngineId(String searchEngineId) {
351 if (_searchEngineId == null) {
352 _searchEngineId = searchEngineId;
353 }
354 }
355
356 public void setSorts(Sort... sorts) {
357 _sorts = sorts;
358 }
359
360 public void setStart(int start) {
361 _start = start;
362 }
363
364 public void setTimeZone(TimeZone timeZone) {
365 _timeZone = timeZone;
366 }
367
368 public void setUserId(long userId) {
369 _userId = userId;
370 }
371
372 private boolean _andSearch;
373 private long[] _assetCategoryIds;
374 private String[] _assetTagNames;
375 private Map<String, Serializable> _attributes;
376 private BooleanClause[] _booleanClauses;
377 private long[] _categoryIds;
378 private long[] _classTypeIds;
379 private boolean _commitImmediately;
380 private long _companyId;
381 private int _end = QueryUtil.ALL_POS;
382 private String[] _entryClassNames;
383 private Map<String, Facet> _facets = new ConcurrentHashMap<String, Facet>();
384 private long[] _folderIds;
385 private long[] _groupIds;
386 private boolean _includeAttachments;
387 private boolean _includeDiscussions;
388 private boolean _includeLiveGroups = true;
389 private boolean _includeStagingGroups = true;
390 private String _keywords;
391 private Layout _layout;
392 private boolean _like;
393 private Locale _locale = LocaleUtil.getMostRelevantLocale();
394 private long[] _nodeIds;
395 private String _originalKeywords;
396 private long _ownerUserId;
397 private String[] _portletIds;
398 private QueryConfig _queryConfig;
399 private boolean _scopeStrict = true;
400 private float _scoresThreshold;
401 private String _searchEngineId;
402 private Sort[] _sorts;
403 private int _start = QueryUtil.ALL_POS;
404 private TimeZone _timeZone;
405 private long _userId;
406
407 }