1
22
23 package com.liferay.portal.kernel.search;
24
25
31 public class SearchEngineUtil {
32
33
37 public static final int ALL_POS = -1;
38
39 public static void addDocument(long companyId, Document doc)
40 throws SearchException {
41
42 if (isIndexReadOnly()) {
43 return;
44 }
45
46 _searchEngine.getWriter().addDocument(companyId, doc);
47 }
48
49 public static void deleteDocument(long companyId, String uid)
50 throws SearchException {
51
52 if (isIndexReadOnly()) {
53 return;
54 }
55
56 _searchEngine.getWriter().deleteDocument(companyId, uid);
57 }
58
59 public static void deletePortletDocuments(long companyId, String portletId)
60 throws SearchException {
61
62 if (isIndexReadOnly()) {
63 return;
64 }
65
66 _searchEngine.getWriter().deletePortletDocuments(companyId, portletId);
67 }
68
69 public static PortalSearchEngine getPortalSearchEngine() {
70 return _portalSearchEngine;
71 }
72
73 public static SearchEngine getSearchEngine() {
74 return _searchEngine;
75 }
76
77 public static boolean isIndexReadOnly() {
78 return _portalSearchEngine.isIndexReadOnly();
79 }
80
81 public static void register(String name) {
82 _searchEngine.register(name);
83 }
84
85 public static void registerDefaultSearchEngine() {
86 SearchEngineUtil.register(_defaultSearchEngineName);
87 }
88
89 public static Hits search(long companyId, Query query, int start, int end)
90 throws SearchException {
91
92 return _searchEngine.getSearcher().search(
93 companyId, query, _DEFAULT_SORT, start, end);
94 }
95
96 public static Hits search(
97 long companyId, Query query, Sort sort, int start, int end)
98 throws SearchException {
99
100 return _searchEngine.getSearcher().search(
101 companyId, query, new Sort[] {sort}, start, end);
102 }
103
104 public static Hits search(
105 long companyId, Query query, Sort[] sorts, int start, int end)
106 throws SearchException {
107
108 return _searchEngine.getSearcher().search(
109 companyId, query, sorts, start, end);
110 }
111
112 public static void setIndexReadOnly(boolean indexReadOnly) {
113 _portalSearchEngine.setIndexReadOnly(indexReadOnly);
114 }
115
116 public static void unregister(String fromName) {
117 _searchEngine.unregister(fromName);
118 }
119
120 public static void updateDocument(long companyId, String uid, Document doc)
121 throws SearchException {
122
123 if (isIndexReadOnly()) {
124 return;
125 }
126
127 _searchEngine.getWriter().updateDocument(companyId, uid, doc);
128 }
129
130 public void setDefaultSearchEngineName(String defaultSearchEngineName) {
131 _defaultSearchEngineName = defaultSearchEngineName;
132 }
133
134 public void setPortalSearchEngine(PortalSearchEngine portalSearchEngine) {
135 _portalSearchEngine = portalSearchEngine;
136 }
137
138 public void setSearchEngine(SearchEngine searchEngine) {
139 _searchEngine = searchEngine;
140 }
141
142 private static final Sort[] _DEFAULT_SORT = new Sort[] {
143 new Sort(null, Sort.SCORE_TYPE, false),
144 new Sort(Field.MODIFIED, Sort.LONG_TYPE, true)
145 };
146
147 private static String _defaultSearchEngineName;
148 private static PortalSearchEngine _portalSearchEngine;
149 private static SearchEngine _searchEngine;
150
151 }