1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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;
24  
25  /**
26   * <a href="SearchEngineUtil.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Bruno Farache
29   *
30   */
31  public class SearchEngineUtil {
32  
33      /**
34       * @deprecated Use
35       * <code>com.liferay.portal.kernel.dao.orm.QueryUtil.ALL_POS</code>.
36       */
37      public static final int ALL_POS = -1;
38  
39      public static void addDocument(long companyId, Document doc)
40          throws SearchException {
41  
42          getSearchEngine().getWriter().addDocument(companyId, doc);
43      }
44  
45      public static void deleteDocument(long companyId, String uid)
46          throws SearchException {
47  
48          getSearchEngine().getWriter().deleteDocument(companyId, uid);
49      }
50  
51      public static void deletePortletDocuments(long companyId, String portletId)
52          throws SearchException {
53  
54          getSearchEngine().getWriter().deletePortletDocuments(
55              companyId, portletId);
56      }
57  
58      public static SearchEngine getSearchEngine() {
59          return _searchEngine;
60      }
61  
62      public static boolean isIndexReadOnly() {
63          return getSearchEngine().isIndexReadOnly();
64      }
65  
66      public static void register(String name) {
67          getSearchEngine().register(name);
68      }
69  
70      public static void registerDefaultSearchEngine() {
71          SearchEngineUtil.register(_defaultSearchEngineName);
72      }
73  
74      public static Hits search(long companyId, Query query, int start, int end)
75          throws SearchException {
76  
77          return getSearchEngine().getSearcher().search(
78              companyId, query, start, end);
79      }
80  
81      public static Hits search(
82              long companyId, Query query, Sort sort, int start, int end)
83          throws SearchException {
84  
85          return getSearchEngine().getSearcher().search(
86              companyId, query, new Sort[] {sort}, start, end);
87      }
88  
89      public static Hits search(
90              long companyId, Query query, Sort[] sorts, int start, int end)
91          throws SearchException {
92  
93          return getSearchEngine().getSearcher().search(
94              companyId, query, sorts, start, end);
95      }
96  
97      public static void unregister(String fromName) {
98          getSearchEngine().unregister(fromName);
99      }
100 
101     public static void updateDocument(long companyId, String uid, Document doc)
102         throws SearchException {
103 
104         getSearchEngine().getWriter().updateDocument(companyId, uid, doc);
105     }
106 
107     public void setDefaultSearchEngineName(String defaultSearchEngineName) {
108         _defaultSearchEngineName = defaultSearchEngineName;
109     }
110 
111     public void setSearchEngine(SearchEngine searchEngine) {
112         _searchEngine = searchEngine;
113     }
114 
115     private static String _defaultSearchEngineName;
116     private static SearchEngine _searchEngine;
117 
118 }