001
014
015 package com.liferay.portlet.directory.util;
016
017 import com.liferay.portal.kernel.search.Document;
018 import com.liferay.portal.kernel.search.HitsOpenSearchImpl;
019 import com.liferay.portal.kernel.search.Indexer;
020 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
021 import com.liferay.portal.kernel.search.SearchException;
022 import com.liferay.portal.kernel.search.Summary;
023 import com.liferay.portal.kernel.util.GetterUtil;
024 import com.liferay.portal.kernel.util.UnicodeProperties;
025 import com.liferay.portal.model.User;
026 import com.liferay.portal.util.PortletKeys;
027 import com.liferay.portlet.expando.model.ExpandoBridge;
028 import com.liferay.portlet.expando.model.ExpandoColumnConstants;
029 import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
030 import com.liferay.portlet.usersadmin.util.UserIndexer;
031
032 import java.util.Enumeration;
033 import java.util.LinkedHashMap;
034 import java.util.Locale;
035
036 import javax.portlet.PortletURL;
037
038 import javax.servlet.http.HttpServletRequest;
039
040
045 public class DirectoryOpenSearchImpl extends HitsOpenSearchImpl {
046
047 public static final String SEARCH_PATH = "/c/directory/open_search";
048
049 public static final String TITLE = "Liferay Directory Search: ";
050
051 @Override
052 public Indexer getIndexer() {
053 return IndexerRegistryUtil.getIndexer(User.class);
054 }
055
056 @Override
057 public String getPortletId() {
058 return UserIndexer.PORTLET_ID;
059 }
060
061 @Override
062 public String getSearchPath() {
063 return SEARCH_PATH;
064 }
065
066 @Override
067 public Summary getSummary(
068 Indexer indexer, Document document, Locale locale, String snippet,
069 PortletURL portletURL)
070 throws SearchException {
071
072 Summary summary = super.getSummary(
073 indexer, document, locale, snippet, portletURL);
074
075 portletURL = summary.getPortletURL();
076
077 portletURL.setParameter("struts_action", "/directory/view_user");
078
079 return summary;
080 }
081
082 @Override
083 public String getTitle(String keywords) {
084 return TITLE + keywords;
085 }
086
087 @Override
088 protected PortletURL getPortletURL(
089 HttpServletRequest request, String portletId, long scopeGroupId)
090 throws Exception {
091
092 return super.getPortletURL(
093 request, PortletKeys.DIRECTORY, scopeGroupId);
094 }
095
096 protected LinkedHashMap<String, Object> getUserParams(
097 long companyId, String keywords) {
098
099 LinkedHashMap<String, Object> userParams =
100 new LinkedHashMap<String, Object>();
101
102 ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(
103 companyId, User.class.getName());
104
105 Enumeration<String> enu = expandoBridge.getAttributeNames();
106
107 while (enu.hasMoreElements()) {
108 String attributeName = enu.nextElement();
109
110 UnicodeProperties properties = expandoBridge.getAttributeProperties(
111 attributeName);
112
113 int indexType = GetterUtil.getInteger(
114 properties.getProperty(ExpandoColumnConstants.INDEX_TYPE));
115
116 if (indexType != ExpandoColumnConstants.INDEX_TYPE_NONE) {
117 userParams.put(attributeName, keywords);
118 }
119 }
120
121 return userParams;
122 }
123
124 }