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 getCompanyId() {
079 return _companyId;
080 }
081
082 public int getEnd() {
083 return _end;
084 }
085
086 public String[] getEntryClassNames() {
087 if (_entryClassNames == null) {
088 _entryClassNames = new String[0];
089 }
090
091 return _entryClassNames;
092 }
093
094 public Facet getFacet(String fieldName) {
095 return _facets.get(fieldName);
096 }
097
098 public Map<String, Facet> getFacets() {
099 return _facets;
100 }
101
102 public long[] getFolderIds() {
103 return _folderIds;
104 }
105
106 public long[] getGroupIds() {
107 return _groupIds;
108 }
109
110 public String getKeywords() {
111 return _keywords;
112 }
113
114 public Locale getLocale() {
115 return _locale;
116 }
117
118 public long[] getNodeIds() {
119 return _nodeIds;
120 }
121
122 public long getOwnerUserId() {
123 return _ownerUserId;
124 }
125
126 public String[] getPortletIds() {
127 return _portletIds;
128 }
129
130 public QueryConfig getQueryConfig() {
131 if (_queryConfig == null) {
132 _queryConfig = new QueryConfig();
133 }
134
135 return _queryConfig;
136 }
137
138 public String getSearchEngineId() {
139 if (Validator.isNull(_searchEngineId)) {
140 return SearchEngineUtil.getDefaultSearchEngineId();
141 }
142
143 return _searchEngineId;
144 }
145
146 public Sort[] getSorts() {
147 return _sorts;
148 }
149
150 public int getStart() {
151 return _start;
152 }
153
154 public TimeZone getTimeZone() {
155 return _timeZone;
156 }
157
158 public long getUserId() {
159 return _userId;
160 }
161
162 public boolean isAndSearch() {
163 return _andSearch;
164 }
165
166 public boolean isIncludeLiveGroups() {
167 return _includeLiveGroups;
168 }
169
170 public boolean isIncludeStagingGroups() {
171 return _includeStagingGroups;
172 }
173
174 public boolean isScopeStrict() {
175 return _scopeStrict;
176 }
177
178 public void setAndSearch(boolean andSearch) {
179 _andSearch = andSearch;
180 }
181
182 public void setAssetCategoryIds(long[] assetCategoryIds) {
183 _assetCategoryIds = assetCategoryIds;
184 }
185
186 public void setAssetTagNames(String[] assetTagNames) {
187 _assetTagNames = assetTagNames;
188 }
189
190 public void setAttribute(String name, Serializable value) {
191 if (_attributes == null) {
192 _attributes = new HashMap<String, Serializable>();
193 }
194
195 _attributes.put(name, value);
196 }
197
198 public void setAttributes(Map<String, Serializable> attributes) {
199 _attributes = attributes;
200 }
201
202 public void setBooleanClauses(BooleanClause[] booleanClauses) {
203 _booleanClauses = booleanClauses;
204 }
205
206 public void setCategoryIds(long[] categoryIds) {
207 _categoryIds = categoryIds;
208 }
209
210 public void setCompanyId(long companyId) {
211 _companyId = companyId;
212 }
213
214 public void setEnd(int end) {
215 _end = end;
216 }
217
218 public void setEntryClassNames(String[] entryClassNames) {
219 _entryClassNames = entryClassNames;
220 }
221
222 public void setFacets(List<Facet> facets) {
223 for (Facet facet : facets) {
224 _facets.put(facet.getFieldName(), facet);
225 }
226 }
227
228 public void setFolderIds(List<Long> folderIds) {
229 _folderIds = ArrayUtil.toArray(
230 folderIds.toArray(new Long[folderIds.size()]));
231 }
232
233 public void setFolderIds(long[] folderIds) {
234 _folderIds = folderIds;
235 }
236
237 public void setGroupIds(long[] groupIds) {
238 _groupIds = groupIds;
239 }
240
241 public void setIncludeLiveGroups(boolean includeLiveGroups) {
242 _includeLiveGroups = includeLiveGroups;
243 }
244
245 public void setIncludeStagingGroups(boolean includeStagingGroups) {
246 _includeStagingGroups = includeStagingGroups;
247 }
248
249 public void setKeywords(String keywords) {
250 _keywords = keywords;
251 }
252
253 public void setLocale(Locale locale) {
254 if (locale != null) {
255 _locale = locale;
256 }
257 }
258
259 public void setNodeIds(long[] nodeIds) {
260 _nodeIds = nodeIds;
261 }
262
263 public void setOwnerUserId(long ownerUserId) {
264 _ownerUserId = ownerUserId;
265 }
266
267 public void setPortletIds(String[] portletIds) {
268 _portletIds = portletIds;
269 }
270
271 public void setQueryConfig(QueryConfig queryConfig) {
272 _queryConfig = queryConfig;
273 }
274
275 public void setScopeStrict(boolean scopeStrict) {
276 _scopeStrict = scopeStrict;
277 }
278
279 public void setSearchEngineId(String searchEngineId) {
280 if (_searchEngineId == null) {
281 _searchEngineId = searchEngineId;
282 }
283 }
284
285 public void setSorts(Sort[] sorts) {
286 _sorts = sorts;
287 }
288
289 public void setStart(int start) {
290 _start = start;
291 }
292
293 public void setTimeZone(TimeZone timeZone) {
294 _timeZone = timeZone;
295 }
296
297 public void setUserId(long userId) {
298 _userId = userId;
299 }
300
301 private boolean _andSearch;
302 private long[] _assetCategoryIds;
303 private String[] _assetTagNames;
304 private Map<String, Serializable> _attributes;
305 private BooleanClause[] _booleanClauses;
306 private long[] _categoryIds;
307 private long _companyId;
308 private int _end = QueryUtil.ALL_POS;
309 private String[] _entryClassNames;
310 private Map<String, Facet> _facets = new ConcurrentHashMap<String, Facet>();
311 private long[] _folderIds;
312 private long[] _groupIds;
313 private boolean _includeLiveGroups = true;
314 private boolean _includeStagingGroups = true;
315 private String _keywords;
316 private Locale _locale = LocaleUtil.getMostRelevantLocale();
317 private long[] _nodeIds;
318 private long _ownerUserId;
319 private String[] _portletIds;
320 private QueryConfig _queryConfig;
321 private boolean _scopeStrict = true;
322 private String _searchEngineId;
323 private Sort[] _sorts;
324 private int _start = QueryUtil.ALL_POS;
325 private TimeZone _timeZone;
326 private long _userId;
327
328 }