001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.directory.util;
016    
017    import com.liferay.portal.kernel.search.HitsOpenSearchImpl;
018    import com.liferay.portal.kernel.search.Indexer;
019    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
020    import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
021    import com.liferay.portal.kernel.util.GetterUtil;
022    import com.liferay.portal.kernel.util.StringPool;
023    import com.liferay.portal.kernel.util.UnicodeProperties;
024    import com.liferay.portal.model.User;
025    import com.liferay.portal.util.PortletKeys;
026    import com.liferay.portlet.expando.model.ExpandoBridge;
027    import com.liferay.portlet.expando.model.ExpandoColumnConstants;
028    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
029    
030    import java.util.Enumeration;
031    import java.util.LinkedHashMap;
032    
033    import javax.portlet.PortletURL;
034    
035    import javax.servlet.http.HttpServletRequest;
036    
037    /**
038     * @author Brian Wing Shun Chan
039     * @author Marcellus Tavares
040     * @author Ryan Park
041     */
042    @OSGiBeanProperties
043    public class DirectoryOpenSearchImpl extends HitsOpenSearchImpl {
044    
045            public static final String TITLE = "Liferay Directory Search: ";
046    
047            @Override
048            public String getClassName() {
049                    return User.class.getName();
050            }
051    
052            @Override
053            public Indexer getIndexer() {
054                    return IndexerRegistryUtil.getIndexer(User.class);
055            }
056    
057            @Override
058            public String getSearchPath() {
059                    return StringPool.BLANK;
060            }
061    
062            @Override
063            public String getTitle(String keywords) {
064                    return TITLE + keywords;
065            }
066    
067            @Override
068            protected PortletURL getPortletURL(
069                            HttpServletRequest request, String portletId, long scopeGroupId)
070                    throws Exception {
071    
072                    return super.getPortletURL(
073                            request, PortletKeys.DIRECTORY, scopeGroupId);
074            }
075    
076            protected LinkedHashMap<String, Object> getUserParams(
077                    long companyId, String keywords) {
078    
079                    LinkedHashMap<String, Object> userParams = new LinkedHashMap<>();
080    
081                    ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(
082                            companyId, User.class.getName());
083    
084                    Enumeration<String> enu = expandoBridge.getAttributeNames();
085    
086                    while (enu.hasMoreElements()) {
087                            String attributeName = enu.nextElement();
088    
089                            UnicodeProperties properties = expandoBridge.getAttributeProperties(
090                                    attributeName);
091    
092                            int indexType = GetterUtil.getInteger(
093                                    properties.getProperty(ExpandoColumnConstants.INDEX_TYPE));
094    
095                            if (indexType != ExpandoColumnConstants.INDEX_TYPE_NONE) {
096                                    userParams.put(attributeName, keywords);
097                            }
098                    }
099    
100                    return userParams;
101            }
102    
103    }