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;
24  
25  /**
26   * <a href="SearchEngineUtil.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Bruno Farache
29   */
30  public class SearchEngineUtil {
31  
32      /**
33       * @deprecated Use {@link
34       *             com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}.
35       */
36      public static final int ALL_POS = -1;
37  
38      public static void addDocument(long companyId, Document doc)
39          throws SearchException {
40  
41          if (isIndexReadOnly()) {
42              return;
43          }
44  
45          _searchEngine.getWriter().addDocument(companyId, doc);
46      }
47  
48      public static void deleteDocument(long companyId, String uid)
49          throws SearchException {
50  
51          if (isIndexReadOnly()) {
52              return;
53          }
54  
55          _searchEngine.getWriter().deleteDocument(companyId, uid);
56      }
57  
58      public static void deletePortletDocuments(long companyId, String portletId)
59          throws SearchException {
60  
61          if (isIndexReadOnly()) {
62              return;
63          }
64  
65          _searchEngine.getWriter().deletePortletDocuments(companyId, portletId);
66      }
67  
68      public static PortalSearchEngine getPortalSearchEngine() {
69          return _portalSearchEngine;
70      }
71  
72      public static SearchEngine getSearchEngine() {
73          return _searchEngine;
74      }
75  
76      public static boolean isIndexReadOnly() {
77          return _portalSearchEngine.isIndexReadOnly();
78      }
79  
80      public static Hits search(long companyId, Query query, int start, int end)
81          throws SearchException {
82  
83          return _searchEngine.getSearcher().search(
84              companyId, query, _DEFAULT_SORT, start, end);
85      }
86  
87      public static Hits search(
88              long companyId, Query query, Sort sort, int start, int end)
89          throws SearchException {
90  
91          return _searchEngine.getSearcher().search(
92              companyId, query, new Sort[] {sort}, start, end);
93      }
94  
95      public static Hits search(
96              long companyId, Query query, Sort[] sorts, int start, int end)
97          throws SearchException {
98  
99          return _searchEngine.getSearcher().search(
100             companyId, query, sorts, start, end);
101     }
102 
103     public static void setIndexReadOnly(boolean indexReadOnly) {
104         _portalSearchEngine.setIndexReadOnly(indexReadOnly);
105     }
106 
107     public static void updateDocument(long companyId, String uid, Document doc)
108         throws SearchException {
109 
110         if (isIndexReadOnly()) {
111             return;
112         }
113 
114         _searchEngine.getWriter().updateDocument(companyId, uid, doc);
115     }
116 
117     public void setPortalSearchEngine(PortalSearchEngine portalSearchEngine) {
118         _portalSearchEngine = portalSearchEngine;
119     }
120 
121     public void setSearchEngine(SearchEngine searchEngine) {
122         _searchEngine = searchEngine;
123     }
124 
125     private static final Sort[] _DEFAULT_SORT = new Sort[] {
126         new Sort(null, Sort.SCORE_TYPE, false),
127         new Sort(Field.MODIFIED, Sort.LONG_TYPE, true)
128     };
129 
130     private static PortalSearchEngine _portalSearchEngine;
131     private static SearchEngine _searchEngine;
132 
133 }