001    /**
002     * Copyright (c) 2000-2013 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    import com.liferay.portal.model.Layout;
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    /**
033     * @author Brian Wing Shun Chan
034     * @author Julio Camarero
035     */
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 Layout getLayout() {
115                    return _layout;
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 isAndSearch() {
167                    return _andSearch;
168            }
169    
170            public boolean isIncludeLiveGroups() {
171                    return _includeLiveGroups;
172            }
173    
174            public boolean isIncludeStagingGroups() {
175                    return _includeStagingGroups;
176            }
177    
178            public boolean isScopeStrict() {
179                    return _scopeStrict;
180            }
181    
182            public void setAndSearch(boolean andSearch) {
183                    _andSearch = andSearch;
184            }
185    
186            public void setAssetCategoryIds(long[] assetCategoryIds) {
187                    _assetCategoryIds = assetCategoryIds;
188            }
189    
190            public void setAssetTagNames(String[] assetTagNames) {
191                    _assetTagNames = assetTagNames;
192            }
193    
194            public void setAttribute(String name, Serializable value) {
195                    if (_attributes == null) {
196                            _attributes = new HashMap<String, Serializable>();
197                    }
198    
199                    _attributes.put(name, value);
200            }
201    
202            public void setAttributes(Map<String, Serializable> attributes) {
203                    _attributes = attributes;
204            }
205    
206            public void setBooleanClauses(BooleanClause[] booleanClauses) {
207                    _booleanClauses = booleanClauses;
208            }
209    
210            public void setCategoryIds(long[] categoryIds) {
211                    _categoryIds = categoryIds;
212            }
213    
214            public void setCompanyId(long companyId) {
215                    _companyId = companyId;
216            }
217    
218            public void setEnd(int end) {
219                    _end = end;
220            }
221    
222            public void setEntryClassNames(String[] entryClassNames) {
223                    _entryClassNames = entryClassNames;
224            }
225    
226            public void setFacets(List<Facet> facets) {
227                    for (Facet facet : facets) {
228                            _facets.put(facet.getFieldName(), facet);
229                    }
230            }
231    
232            public void setFolderIds(long[] folderIds) {
233                    _folderIds = folderIds;
234            }
235    
236            public void setGroupIds(long[] groupIds) {
237                    _groupIds = groupIds;
238            }
239    
240            public void setIncludeLiveGroups(boolean includeLiveGroups) {
241                    _includeLiveGroups = includeLiveGroups;
242            }
243    
244            public void setIncludeStagingGroups(boolean includeStagingGroups) {
245                    _includeStagingGroups = includeStagingGroups;
246            }
247    
248            public void setKeywords(String keywords) {
249                    _keywords = keywords;
250            }
251    
252            public void setLayout(Layout layout) {
253                    _layout = layout;
254            }
255    
256            public void setLocale(Locale locale) {
257                    if (locale != null) {
258                            _locale = locale;
259                    }
260            }
261    
262            public void setNodeIds(long[] nodeIds) {
263                    _nodeIds = nodeIds;
264            }
265    
266            public void setOwnerUserId(long ownerUserId) {
267                    _ownerUserId = ownerUserId;
268            }
269    
270            public void setPortletIds(String[] portletIds) {
271                    _portletIds = portletIds;
272            }
273    
274            public void setQueryConfig(QueryConfig queryConfig) {
275                    _queryConfig = queryConfig;
276            }
277    
278            public void setScopeStrict(boolean scopeStrict) {
279                    _scopeStrict = scopeStrict;
280            }
281    
282            public void setSearchEngineId(String searchEngineId) {
283                    if (_searchEngineId == null) {
284                            _searchEngineId = searchEngineId;
285                    }
286            }
287    
288            public void setSorts(Sort[] sorts) {
289                    _sorts = sorts;
290            }
291    
292            public void setStart(int start) {
293                    _start = start;
294            }
295    
296            public void setTimeZone(TimeZone timeZone) {
297                    _timeZone = timeZone;
298            }
299    
300            public void setUserId(long userId) {
301                    _userId = userId;
302            }
303    
304            private boolean _andSearch;
305            private long[] _assetCategoryIds;
306            private String[] _assetTagNames;
307            private Map<String, Serializable> _attributes;
308            private BooleanClause[] _booleanClauses;
309            private long[] _categoryIds;
310            private long _companyId;
311            private int _end = QueryUtil.ALL_POS;
312            private String[] _entryClassNames;
313            private Map<String, Facet> _facets = new ConcurrentHashMap<String, Facet>();
314            private long[] _folderIds;
315            private long[] _groupIds;
316            private boolean _includeLiveGroups = true;
317            private boolean _includeStagingGroups = true;
318            private String _keywords;
319            private Layout _layout;
320            private Locale _locale = LocaleUtil.getMostRelevantLocale();
321            private long[] _nodeIds;
322            private long _ownerUserId;
323            private String[] _portletIds;
324            private QueryConfig _queryConfig;
325            private boolean _scopeStrict = true;
326            private String _searchEngineId;
327            private Sort[] _sorts;
328            private int _start = QueryUtil.ALL_POS;
329            private TimeZone _timeZone;
330            private long _userId;
331    
332    }