1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.search.messaging;
16  
17  import com.liferay.portal.kernel.search.Document;
18  import com.liferay.portal.kernel.search.Query;
19  import com.liferay.portal.kernel.search.Sort;
20  import com.liferay.portal.kernel.util.StringBundler;
21  
22  import java.io.Serializable;
23  
24  import java.util.Arrays;
25  import java.util.Collection;
26  
27  /**
28   * <a href="SearchRequest.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Bruno Farache
31   */
32  public class SearchRequest implements Serializable {
33  
34      public static SearchRequest addDocument(long companyId, Document document) {
35          SearchRequest searchRequest = new SearchRequest(
36              SearchEngineCommand.ADD_DOCUMENT);
37  
38          searchRequest.setCompanyId(companyId);
39          searchRequest.setDocument(document);
40  
41          return searchRequest;
42      }
43  
44      public static SearchRequest addDocuments(
45          long companyId, Collection<Document> documents) {
46  
47          SearchRequest searchRequest = new SearchRequest(
48              SearchEngineCommand.ADD_DOCUMENTS);
49  
50          searchRequest.setCompanyId(companyId);
51          searchRequest.setDocuments(documents);
52  
53          return searchRequest;
54      }
55  
56      public static SearchRequest deleteDocument(long companyId, String uid) {
57          SearchRequest searchRequest = new SearchRequest(
58              SearchEngineCommand.DELETE_DOCUMENT);
59  
60          searchRequest.setCompanyId(companyId);
61          searchRequest.setId(uid);
62  
63          return searchRequest;
64      }
65  
66      public static SearchRequest deleteDocuments(
67          long companyId, Collection<String> uids) {
68  
69          SearchRequest searchRequest = new SearchRequest(
70              SearchEngineCommand.DELETE_DOCUMENTS);
71  
72          searchRequest.setCompanyId(companyId);
73          searchRequest.setIds(uids);
74  
75          return searchRequest;
76      }
77  
78      public static SearchRequest deletePortletDocuments(
79          long companyId, String portletId) {
80  
81          SearchRequest searchRequest = new SearchRequest(
82              SearchEngineCommand.DELETE_PORTLET_DOCUMENTS);
83  
84          searchRequest.setCompanyId(companyId);
85          searchRequest.setId(portletId);
86  
87          return searchRequest;
88      }
89  
90      public static SearchRequest search(
91          long companyId, Query query, Sort[] sorts, int start, int end) {
92  
93          SearchRequest searchRequest = new SearchRequest(
94              SearchEngineCommand.SEARCH);
95  
96          searchRequest.setCompanyId(companyId);
97          searchRequest.setEnd(end);
98          searchRequest.setQuery(query);
99          searchRequest.setSorts(sorts);
100         searchRequest.setStart(start);
101 
102         return searchRequest;
103     }
104 
105     public static SearchRequest updateDocument(
106         long companyId, Document document) {
107 
108         SearchRequest searchRequest = new SearchRequest(
109             SearchEngineCommand.UPDATE_DOCUMENT);
110 
111         searchRequest.setCompanyId(companyId);
112         searchRequest.setDocument(document);
113 
114         return searchRequest;
115     }
116 
117     public static SearchRequest updateDocuments(
118         long companyId, Collection<Document> documents) {
119 
120         SearchRequest searchRequest = new SearchRequest(
121             SearchEngineCommand.UPDATE_DOCUMENTS);
122 
123         searchRequest.setCompanyId(companyId);
124         searchRequest.setDocuments(documents);
125 
126         return searchRequest;
127     }
128 
129     private SearchRequest(SearchEngineCommand searchEngineCommand) {
130         _searchEngineCommand = searchEngineCommand;
131     }
132 
133     public long getCompanyId() {
134         return _companyId;
135     }
136 
137     public Document getDocument() {
138         return _document;
139     }
140 
141     public Collection<Document> getDocuments() {
142         return _documents;
143     }
144 
145     public int getEnd() {
146         return _end;
147     }
148 
149     public String getId() {
150         return _id;
151     }
152 
153     public Collection<String> getIds() {
154         return _ids;
155     }
156 
157     public Query getQuery() {
158         return _query;
159     }
160 
161     public SearchEngineCommand getSearchEngineCommand() {
162         return _searchEngineCommand;
163     }
164 
165     public Sort[] getSorts() {
166         return _sorts;
167     }
168 
169     public int getStart() {
170         return _start;
171     }
172 
173     public void setCompanyId(long companyId) {
174         _companyId = companyId;
175     }
176 
177     public void setDocument(Document document) {
178         _document = document;
179     }
180 
181     public void setDocuments(Collection<Document> documents) {
182         _documents = documents;
183     }
184 
185     public void setEnd(int end) {
186         _end = end;
187     }
188 
189     public void setId(String id) {
190         _id = id;
191     }
192 
193     public void setIds(Collection<String> ids) {
194         _ids = ids;
195     }
196 
197     public void setQuery(Query query) {
198         _query = query;
199     }
200 
201     public void setSorts(Sort[] sorts) {
202         _sorts = sorts;
203     }
204 
205     public void setStart(int start) {
206         _start = start;
207     }
208 
209     public String toString() {
210         StringBundler sb = new StringBundler(17);
211 
212         sb.append("{companyId=");
213         sb.append(_companyId);
214         sb.append(", document=");
215         sb.append(_document);
216         sb.append(", documents=");
217         sb.append(_documents);
218         sb.append(", end=");
219         sb.append(_end);
220         sb.append(", id=");
221         sb.append(_id);
222         sb.append(", ids=");
223         sb.append(_ids);
224         sb.append(", query=");
225         sb.append(_query);
226         sb.append(", searchEngineCommand=");
227         sb.append(_searchEngineCommand);
228         sb.append(", sorts=");
229         sb.append(Arrays.toString(_sorts));
230         sb.append(", start=");
231         sb.append(_start);
232         sb.append("}");
233 
234         return sb.toString();
235     }
236 
237     private long _companyId;
238     private Document _document;
239     private Collection<Document> _documents;
240     private int _end;
241     private String _id;
242     private Collection<String> _ids;
243     private Query _query;
244     private SearchEngineCommand _searchEngineCommand;
245     private Sort[] _sorts;
246     private int _start;
247 
248 }