001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.LocaleUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    
022    import java.io.Serializable;
023    
024    import java.util.HashMap;
025    import java.util.List;
026    import java.util.Locale;
027    import java.util.Map;
028    import java.util.TimeZone;
029    import java.util.concurrent.ConcurrentHashMap;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     * @author Julio Camarero
034     */
035    public class SearchContext implements Serializable {
036    
037            public void addFacet(Facet facet) {
038                    if (facet == null) {
039                            return;
040                    }
041    
042                    _facets.put(facet.getFieldName(), facet);
043            }
044    
045            public long[] getAssetCategoryIds() {
046                    return _assetCategoryIds;
047            }
048    
049            public String[] getAssetTagNames() {
050                    return _assetTagNames;
051            }
052    
053            public Serializable getAttribute(String name) {
054                    if (_attributes == null) {
055                            return null;
056                    }
057    
058                    return _attributes.get(name);
059            }
060    
061            public Map<String, Serializable> getAttributes() {
062                    if (_attributes == null) {
063                            _attributes = new HashMap<String, Serializable>();
064                    }
065    
066                    return _attributes;
067            }
068    
069            public BooleanClause[] getBooleanClauses() {
070                    return _booleanClauses;
071            }
072    
073            public long[] getCategoryIds() {
074                    return _categoryIds;
075            }
076    
077            public long getCompanyId() {
078                    return _companyId;
079            }
080    
081            public int getEnd() {
082                    return _end;
083            }
084    
085            public String[] getEntryClassNames() {
086                    if (_entryClassNames == null) {
087                            _entryClassNames = new String[0];
088                    }
089    
090                    return _entryClassNames;
091            }
092    
093            public Facet getFacet(String fieldName) {
094                    return _facets.get(fieldName);
095            }
096    
097            public Map<String, Facet> getFacets() {
098                    return _facets;
099            }
100    
101            public long[] getFolderIds() {
102                    return _folderIds;
103            }
104    
105            public long[] getGroupIds() {
106                    return _groupIds;
107            }
108    
109            public String getKeywords() {
110                    return _keywords;
111            }
112    
113            public Locale getLocale() {
114                    return _locale;
115            }
116    
117            public long[] getNodeIds() {
118                    return _nodeIds;
119            }
120    
121            public long getOwnerUserId() {
122                    return _ownerUserId;
123            }
124    
125            public String[] getPortletIds() {
126                    return _portletIds;
127            }
128    
129            public QueryConfig getQueryConfig() {
130                    if (_queryConfig == null) {
131                            _queryConfig = new QueryConfig();
132                    }
133    
134                    return _queryConfig;
135            }
136    
137            public String getSearchEngineId() {
138                    if (Validator.isNull(_searchEngineId)) {
139                            return SearchEngineUtil.SYSTEM_ENGINE_ID;
140                    }
141    
142                    return _searchEngineId;
143            }
144    
145            public Sort[] getSorts() {
146                    return _sorts;
147            }
148    
149            public int getStart() {
150                    return _start;
151            }
152    
153            public TimeZone getTimeZone() {
154                    return _timeZone;
155            }
156    
157            public long getUserId() {
158                    return _userId;
159            }
160    
161            public boolean isAndSearch() {
162                    return _andSearch;
163            }
164    
165            public boolean isIncludeLiveGroups() {
166                    return _includeLiveGroups;
167            }
168    
169            public boolean isIncludeStagingGroups() {
170                    return _includeStagingGroups;
171            }
172    
173            public boolean isScopeStrict() {
174                    return _scopeStrict;
175            }
176    
177            public void setAndSearch(boolean andSearch) {
178                    _andSearch = andSearch;
179            }
180    
181            public void setAssetCategoryIds(long[] assetCategoryIds) {
182                    _assetCategoryIds = assetCategoryIds;
183            }
184    
185            public void setAssetTagNames(String[] assetTagNames) {
186                    _assetTagNames = assetTagNames;
187            }
188    
189            public void setAttribute(String name, Serializable value) {
190                    if (_attributes == null) {
191                            _attributes = new HashMap<String, Serializable>();
192                    }
193    
194                    _attributes.put(name, value);
195            }
196    
197            public void setAttributes(Map<String, Serializable> attributes) {
198                    _attributes = attributes;
199            }
200    
201            public void setBooleanClauses(BooleanClause[] booleanClauses) {
202                    _booleanClauses = booleanClauses;
203            }
204    
205            public void setCategoryIds(long[] categoryIds) {
206                    _categoryIds = categoryIds;
207            }
208    
209            public void setCompanyId(long companyId) {
210                    _companyId = companyId;
211            }
212    
213            public void setEnd(int end) {
214                    _end = end;
215            }
216    
217            public void setEntryClassNames(String[] entryClassNames) {
218                    _entryClassNames = entryClassNames;
219            }
220    
221            public void setFacets(List<Facet> facets) {
222                    for (Facet facet : facets) {
223                            _facets.put(facet.getFieldName(), facet);
224                    }
225            }
226    
227            public void setFolderIds(long[] folderIds) {
228                    _folderIds = folderIds;
229            }
230    
231            public void setGroupIds(long[] groupIds) {
232                    _groupIds = groupIds;
233            }
234    
235            public void setIncludeLiveGroups(boolean includeLiveGroups) {
236                    _includeLiveGroups = includeLiveGroups;
237            }
238    
239            public void setIncludeStagingGroups(boolean includeStagingGroups) {
240                    _includeStagingGroups = includeStagingGroups;
241            }
242    
243            public void setKeywords(String keywords) {
244                    _keywords = keywords;
245            }
246    
247            public void setLocale(Locale locale) {
248                    if (locale != null) {
249                            _locale = locale;
250                    }
251            }
252    
253            public void setNodeIds(long[] nodeIds) {
254                    _nodeIds = nodeIds;
255            }
256    
257            public void setOwnerUserId(long ownerUserId) {
258                    _ownerUserId = ownerUserId;
259            }
260    
261            public void setPortletIds(String[] portletIds) {
262                    _portletIds = portletIds;
263            }
264    
265            public void setQueryConfig(QueryConfig queryConfig) {
266                    _queryConfig = queryConfig;
267            }
268    
269            public void setScopeStrict(boolean scopeStrict) {
270                    _scopeStrict = scopeStrict;
271            }
272    
273            public void setSearchEngineId(String searchEngineId) {
274                    if (_searchEngineId == null) {
275                            _searchEngineId = searchEngineId;
276                    }
277            }
278    
279            public void setSorts(Sort[] sorts) {
280                    _sorts = sorts;
281            }
282    
283            public void setStart(int start) {
284                    _start = start;
285            }
286    
287            public void setTimeZone(TimeZone timeZone) {
288                    _timeZone = timeZone;
289            }
290    
291            public void setUserId(long userId) {
292                    _userId = userId;
293            }
294    
295            private boolean _andSearch;
296            private long[] _assetCategoryIds;
297            private String[] _assetTagNames;
298            private Map<String, Serializable> _attributes;
299            private BooleanClause[] _booleanClauses;
300            private long[] _categoryIds;
301            private long _companyId;
302            private int _end = QueryUtil.ALL_POS;
303            private String[] _entryClassNames;
304            private Map<String, Facet> _facets = new ConcurrentHashMap<String, Facet>();
305            private long[] _folderIds;
306            private long[] _groupIds;
307            private boolean _includeLiveGroups = true;
308            private boolean _includeStagingGroups = true;
309            private String _keywords;
310            private Locale _locale = LocaleUtil.getDefault();
311            private long[] _nodeIds;
312            private long _ownerUserId;
313            private String[] _portletIds;
314            private QueryConfig _queryConfig;
315            private boolean _scopeStrict = true;
316            private String _searchEngineId;
317            private Sort[] _sorts;
318            private int _start = QueryUtil.ALL_POS;
319            private TimeZone _timeZone;
320            private long _userId;
321    
322    }