1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.kernel.search;
21  
22  /**
23   * <a href="SearchEngineUtil.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Bruno Farache
26   *
27   */
28  public class SearchEngineUtil {
29  
30      /**
31       * @deprecated Use
32       * <code>com.liferay.portal.kernel.dao.orm.QueryUtil.ALL_POS</code>.
33       */
34      public static final int ALL_POS = -1;
35  
36      public static void addDocument(long companyId, Document doc)
37          throws SearchException {
38  
39          getSearchEngine().getWriter().addDocument(companyId, doc);
40      }
41  
42      public static void deleteDocument(long companyId, String uid)
43          throws SearchException {
44  
45          getSearchEngine().getWriter().deleteDocument(companyId, uid);
46      }
47  
48      public static void deletePortletDocuments(long companyId, String portletId)
49          throws SearchException {
50  
51          getSearchEngine().getWriter().deletePortletDocuments(
52              companyId, portletId);
53      }
54  
55      public static SearchEngine getSearchEngine() {
56          return _searchEngine;
57      }
58  
59      public static boolean isIndexReadOnly() {
60          return getSearchEngine().isIndexReadOnly();
61      }
62  
63      public static void register(String name) {
64          getSearchEngine().register(name);
65      }
66  
67      public static void registerDefaultSearchEngine() {
68          SearchEngineUtil.register(_defaultSearchEngineName);
69      }
70  
71      public static Hits search(long companyId, Query query, int start, int end)
72          throws SearchException {
73  
74          return getSearchEngine().getSearcher().search(
75              companyId, query, _DEFAULT_SORT, start, end);
76      }
77  
78      public static Hits search(
79              long companyId, Query query, Sort sort, int start, int end)
80          throws SearchException {
81  
82          return getSearchEngine().getSearcher().search(
83              companyId, query, new Sort[] {sort}, start, end);
84      }
85  
86      public static Hits search(
87              long companyId, Query query, Sort[] sorts, int start, int end)
88          throws SearchException {
89  
90          return getSearchEngine().getSearcher().search(
91              companyId, query, sorts, start, end);
92      }
93  
94      public static void unregister(String fromName) {
95          getSearchEngine().unregister(fromName);
96      }
97  
98      public static void updateDocument(long companyId, String uid, Document doc)
99          throws SearchException {
100 
101         getSearchEngine().getWriter().updateDocument(companyId, uid, doc);
102     }
103 
104     public void setDefaultSearchEngineName(String defaultSearchEngineName) {
105         _defaultSearchEngineName = defaultSearchEngineName;
106     }
107 
108     public void setSearchEngine(SearchEngine searchEngine) {
109         _searchEngine = searchEngine;
110     }
111 
112     private static final Sort[] _DEFAULT_SORT = new Sort[] {
113         new Sort(Field.MODIFIED, Sort.LONG_TYPE, true)
114     };
115 
116     private static String _defaultSearchEngineName;
117     private static SearchEngine _searchEngine;
118 
119 }