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  
26  /**
27   * <a href="SearchRequest.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Bruno Farache
30   */
31  public class SearchRequest implements Serializable {
32  
33      public static SearchRequest add(long companyId, Document document) {
34          SearchRequest searchRequest = new SearchRequest(
35              SearchEngineCommand.ADD);
36  
37          searchRequest.setCompanyId(companyId);
38          searchRequest.setDocument(document);
39  
40          return searchRequest;
41      }
42  
43      public static SearchRequest delete(long companyId, String uid) {
44          SearchRequest searchRequest = new SearchRequest(
45              SearchEngineCommand.DELETE);
46  
47          searchRequest.setCompanyId(companyId);
48          searchRequest.setId(uid);
49  
50          return searchRequest;
51      }
52  
53      public static SearchRequest deletePortletDocuments(
54          long companyId, String portletId) {
55  
56          SearchRequest searchRequest = new SearchRequest(
57              SearchEngineCommand.DELETE_PORTLET_DOCUMENTS);
58  
59          searchRequest.setCompanyId(companyId);
60          searchRequest.setId(portletId);
61  
62          return searchRequest;
63      }
64  
65      public static SearchRequest search(
66          long companyId, Query query, Sort[] sorts, int start, int end) {
67  
68          SearchRequest searchRequest = new SearchRequest(
69              SearchEngineCommand.SEARCH);
70  
71          searchRequest.setCompanyId(companyId);
72          searchRequest.setQuery(query);
73          searchRequest.setSorts(sorts);
74          searchRequest.setStart(start);
75          searchRequest.setEnd(end);
76  
77          return searchRequest;
78      }
79  
80      public static SearchRequest update(
81          long companyId, String uid, Document document) {
82  
83          SearchRequest searchRequest = new SearchRequest(
84              SearchEngineCommand.UPDATE);
85  
86          searchRequest.setCompanyId(companyId);
87          searchRequest.setId(uid);
88          searchRequest.setDocument(document);
89  
90          return searchRequest;
91      }
92  
93      public long getCompanyId() {
94          return _companyId;
95      }
96  
97      public Document getDocument() {
98          return _document;
99      }
100 
101     public int getEnd() {
102         return _end;
103     }
104 
105     public String getId() {
106         return _id;
107     }
108 
109     public Query getQuery() {
110         return _query;
111     }
112 
113     public SearchEngineCommand getSearchEngineCommand() {
114         return _searchEngineCommand;
115     }
116 
117     public Sort[] getSorts() {
118         return _sorts;
119     }
120 
121     public int getStart() {
122         return _start;
123     }
124 
125     public void setCompanyId(long companyId) {
126         _companyId = companyId;
127     }
128 
129     public void setDocument(Document document) {
130         _document = document;
131     }
132 
133     public void setEnd(int end) {
134         _end = end;
135     }
136 
137     public void setId(String id) {
138         _id = id;
139     }
140 
141     public void setQuery(Query query) {
142         _query = query;
143     }
144 
145     public void setSorts(Sort[] sorts) {
146         _sorts = sorts;
147     }
148 
149     public void setStart(int start) {
150         _start = start;
151     }
152 
153     public String toString() {
154         StringBundler sb = new StringBundler(17);
155 
156         sb.append("{searchEngineCommand=");
157         sb.append(_searchEngineCommand);
158         sb.append(", companyId=");
159         sb.append(_companyId);
160         sb.append(", id=");
161         sb.append(_id);
162         sb.append(", document=");
163         sb.append(_document);
164         sb.append(", query=");
165         sb.append(_query);
166         sb.append(", sorts=");
167         sb.append(Arrays.toString(_sorts));
168         sb.append(", start=");
169         sb.append(_start);
170         sb.append(", end=");
171         sb.append(_end);
172         sb.append("}");
173 
174         return sb.toString();
175     }
176 
177     private SearchRequest(SearchEngineCommand searchEngineCommand) {
178         _searchEngineCommand = searchEngineCommand;
179     }
180 
181     private long _companyId;
182     private Document _document;
183     private int _end;
184     private String _id;
185     private Query _query;
186     private SearchEngineCommand _searchEngineCommand;
187     private Sort[] _sorts;
188     private int _start;
189 
190 }