1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
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  /**
36   * <a href="DirectoryOpenSearchImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   */
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 }