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