1
14
15 package com.liferay.portlet.directory.util;
16
17 import com.liferay.portal.SystemException;
18 import com.liferay.portal.kernel.search.Document;
19 import com.liferay.portal.kernel.search.DocumentSummary;
20 import com.liferay.portal.kernel.search.Hits;
21 import com.liferay.portal.kernel.search.Indexer;
22 import com.liferay.portal.kernel.search.Sort;
23 import com.liferay.portal.search.HitsOpenSearchImpl;
24 import com.liferay.portal.service.UserLocalServiceUtil;
25 import com.liferay.portal.theme.ThemeDisplay;
26 import com.liferay.portal.util.PortletKeys;
27 import com.liferay.portlet.PortletURLImpl;
28
29 import javax.portlet.PortletModeException;
30 import javax.portlet.PortletURL;
31 import javax.portlet.WindowStateException;
32
33 import javax.servlet.http.HttpServletRequest;
34
35
40 public class DirectoryOpenSearchImpl extends HitsOpenSearchImpl {
41
42 public static final String SEARCH_PATH = "/c/directory/open_search";
43
44 public static final String TITLE = "Liferay Directory Search: ";
45
46 public DocumentSummary getDocumentSummary(
47 Indexer indexer, Document document, String snippet,
48 PortletURL portletURL) {
49
50 DocumentSummary documentSummary = super.getDocumentSummary(
51 indexer, document, snippet, portletURL);
52
53 portletURL = documentSummary.getURL();
54
55 portletURL.setParameter("struts_action", "/directory/view_user");
56
57 return documentSummary;
58 }
59
60 public Hits getHits(
61 long companyId, long groupId, long userId, String keywords,
62 int start, int end)
63 throws Exception {
64
65 Sort sort = new Sort("lastName", Sort.STRING_TYPE, true);
66
67 return UserLocalServiceUtil.search(
68 companyId, userId, keywords, Boolean.TRUE, null, start, end, sort);
69 }
70
71 protected PortletURL getPortletURL(
72 HttpServletRequest request, String portletId, long groupId)
73 throws PortletModeException, SystemException, WindowStateException {
74
75 portletId = PortletKeys.DIRECTORY;
76
77 return super.getPortletURL(request, portletId, groupId);
78 }
79
80 protected String getURL(
81 ThemeDisplay themeDisplay, long groupId, Document result,
82 PortletURL portletURL)
83 throws Exception {
84
85 PortletURLImpl portletURLImpl = (PortletURLImpl)portletURL;
86
87 portletURLImpl.setPortletId(PortletKeys.DIRECTORY);
88
89 return portletURLImpl.toString();
90 }
91
92 public String getSearchPath() {
93 return SEARCH_PATH;
94 }
95
96 public String getTitle(String keywords) {
97 return TITLE + keywords;
98 }
99
100 }