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.search.lucene;
21  
22  import com.liferay.portal.kernel.search.Document;
23  import com.liferay.portal.kernel.search.Hits;
24  import com.liferay.portal.kernel.search.Query;
25  import com.liferay.portal.kernel.search.SearchEngine;
26  import com.liferay.portal.kernel.search.SearchException;
27  import com.liferay.portal.kernel.search.Sort;
28  
29  /**
30   * <a href="LuceneSearchEngineUtil.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Bruno Farache
33   *
34   */
35  public class LuceneSearchEngineUtil {
36  
37      public static void addDocument(long companyId, Document doc)
38          throws SearchException {
39  
40          getSearchEngine().getWriter().addDocument(companyId, doc);
41      }
42  
43      public static void deleteDocument(long companyId, String uid)
44          throws SearchException {
45  
46          getSearchEngine().getWriter().deleteDocument(companyId, uid);
47      }
48  
49      public static void deletePortletDocuments(long companyId, String portletId)
50          throws SearchException {
51  
52          getSearchEngine().getWriter().deletePortletDocuments(
53              companyId, portletId);
54      }
55  
56      public static SearchEngine getSearchEngine() {
57          return _searchEngine;
58      }
59  
60      public static boolean isIndexReadOnly() {
61          return getSearchEngine().isIndexReadOnly();
62      }
63  
64      public static boolean isRegistered() {
65          return getSearchEngine().isRegistered();
66      }
67  
68      public static void register(String name) {
69          getSearchEngine().register(name);
70      }
71  
72      public static Hits search(
73              long companyId, Query query, Sort[] sorts, int start, int end)
74          throws SearchException {
75  
76          return getSearchEngine().getSearcher().search(
77              companyId, query, sorts, start, end);
78      }
79  
80      public static void unregister(String fromName) {
81          getSearchEngine().unregister(fromName);
82      }
83  
84      public static void updateDocument(long companyId, String uid, Document doc)
85          throws SearchException {
86  
87          getSearchEngine().getWriter().updateDocument(companyId, uid, doc);
88      }
89  
90      public void setSearchEngine(SearchEngine searchEngine) {
91          _searchEngine = searchEngine;
92      }
93  
94      private static SearchEngine _searchEngine;
95  
96  }