1
22
23 package com.liferay.portal.kernel.search;
24
25
30 public class SearchEngineUtil {
31
32
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 }