1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.search.messaging;
24  
25  import com.liferay.portal.kernel.search.Document;
26  import com.liferay.portal.kernel.search.Query;
27  import com.liferay.portal.kernel.search.Sort;
28  
29  import java.io.Serializable;
30  
31  /**
32   * <a href="SearchRequest.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Bruno Farache
35   */
36  public class SearchRequest implements Serializable {
37  
38      public static SearchRequest add(long companyId, Document document) {
39          SearchRequest searchRequest = new SearchRequest(
40              SearchEngineCommand.ADD);
41  
42          searchRequest.setCompanyId(companyId);
43          searchRequest.setDocument(document);
44  
45          return searchRequest;
46      }
47  
48      public static SearchRequest delete(long companyId, String uid) {
49          SearchRequest searchRequest = new SearchRequest(
50              SearchEngineCommand.DELETE);
51  
52          searchRequest.setCompanyId(companyId);
53          searchRequest.setId(uid);
54  
55          return searchRequest;
56      }
57  
58      public static SearchRequest deletePortletDocuments(
59          long companyId, String portletId) {
60  
61          SearchRequest searchRequest = new SearchRequest(
62              SearchEngineCommand.DELETE_PORTLET_DOCUMENTS);
63  
64          searchRequest.setCompanyId(companyId);
65          searchRequest.setId(portletId);
66  
67          return searchRequest;
68      }
69  
70      public static SearchRequest search(
71          long companyId, Query query, Sort[] sorts, int start, int end) {
72  
73          SearchRequest searchRequest = new SearchRequest(
74              SearchEngineCommand.SEARCH);
75  
76          searchRequest.setCompanyId(companyId);
77          searchRequest.setQuery(query);
78          searchRequest.setSorts(sorts);
79          searchRequest.setStart(start);
80          searchRequest.setEnd(end);
81  
82          return searchRequest;
83      }
84  
85      public static SearchRequest update(
86          long companyId, String uid, Document document) {
87  
88          SearchRequest searchRequest = new SearchRequest(
89              SearchEngineCommand.UPDATE);
90  
91          searchRequest.setCompanyId(companyId);
92          searchRequest.setId(uid);
93          searchRequest.setDocument(document);
94  
95          return searchRequest;
96      }
97  
98      public long getCompanyId() {
99          return _companyId;
100     }
101 
102     public Document getDocument() {
103         return _document;
104     }
105 
106     public int getEnd() {
107         return _end;
108     }
109 
110     public String getId() {
111         return _id;
112     }
113 
114     public Query getQuery() {
115         return _query;
116     }
117 
118     public SearchEngineCommand getSearchEngineCommand() {
119         return _searchEngineCommand;
120     }
121 
122     public Sort[] getSorts() {
123         return _sorts;
124     }
125 
126     public int getStart() {
127         return _start;
128     }
129 
130     public void setCompanyId(long companyId) {
131         _companyId = companyId;
132     }
133 
134     public void setDocument(Document document) {
135         _document = document;
136     }
137 
138     public void setEnd(int end) {
139         _end = end;
140     }
141 
142     public void setId(String id) {
143         _id = id;
144     }
145 
146     public void setQuery(Query query) {
147         _query = query;
148     }
149 
150     public void setSorts(Sort[] sorts) {
151         _sorts = sorts;
152     }
153 
154     public void setStart(int start) {
155         _start = start;
156     }
157 
158     public String toString() {
159         StringBuilder sb = new StringBuilder();
160 
161         sb.append("{searchEngineCommand=");
162         sb.append(_searchEngineCommand);
163         sb.append(", companyId=");
164         sb.append(_companyId);
165         sb.append(", id=");
166         sb.append(_id);
167         sb.append(", document=");
168         sb.append(_document);
169         sb.append(", query=");
170         sb.append(_query);
171         sb.append(", sorts=");
172         sb.append(_sorts);
173         sb.append(", start=");
174         sb.append(_start);
175         sb.append(", end=");
176         sb.append(_end);
177         sb.append("}");
178 
179         return sb.toString();
180     }
181 
182     private SearchRequest(SearchEngineCommand searchEngineCommand) {
183         _searchEngineCommand = searchEngineCommand;
184     }
185 
186     private long _companyId;
187     private Document _document;
188     private int _end;
189     private String _id;
190     private Query _query;
191     private SearchEngineCommand _searchEngineCommand;
192     private Sort[] _sorts;
193     private int _start;
194 
195 }