/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portal.search.web.internal.facet; import com.liferay.portal.kernel.json.JSONFactoryUtil; import com.liferay.portal.kernel.json.JSONObject; import com.liferay.portal.kernel.search.Field; import com.liferay.portal.kernel.search.facet.MultiValueFacet; import com.liferay.portal.kernel.search.facet.MultiValueFacetFactory; import com.liferay.portal.kernel.search.facet.config.FacetConfiguration; import com.liferay.portal.kernel.search.facet.util.FacetFactory; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.search.web.facet.BaseJSPSearchFacet; import com.liferay.portal.search.web.facet.SearchFacet; import javax.portlet.ActionRequest; import javax.servlet.ServletContext; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** * @author Eudaldo Alonso */ @Component(immediate = true, service = SearchFacet.class) public class AssetTagsSearchFacet extends BaseJSPSearchFacet { @Override public String getConfigurationJspPath() { return "/facets/configuration/asset_tags.jsp"; } @Override public FacetConfiguration getDefaultConfiguration(long companyId) { FacetConfiguration facetConfiguration = new FacetConfiguration(); facetConfiguration.setClassName(getFacetClassName()); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("displayStyle", "list"); jsonObject.put("frequencyThreshold", 1); jsonObject.put("maxTerms", 10); jsonObject.put("showAssetCount", true); facetConfiguration.setDataJSONObject(jsonObject); facetConfiguration.setFieldName(getFieldName()); facetConfiguration.setLabel(getLabel()); facetConfiguration.setOrder(getOrder()); facetConfiguration.setStatic(false); facetConfiguration.setWeight(1.4); return facetConfiguration; } @Override public String getDisplayJspPath() { return "/facets/view/asset_tags.jsp"; } @Override public String getFacetClassName() { return MultiValueFacet.class.getName(); } @Override public String getFieldName() { return Field.ASSET_TAG_NAMES; } @Override public JSONObject getJSONData(ActionRequest actionRequest) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); String displayStyleFacet = ParamUtil.getString( actionRequest, getClassName() + "displayStyleFacet", "list"); int frequencyThreshold = ParamUtil.getInteger( actionRequest, getClassName() + "frequencyThreshold", 1); int maxTerms = ParamUtil.getInteger( actionRequest, getClassName() + "maxTerms", 10); boolean showAssetCount = ParamUtil.getBoolean( actionRequest, getClassName() + "showAssetCount", true); jsonObject.put("displayStyle", displayStyleFacet); jsonObject.put("frequencyThreshold", frequencyThreshold); jsonObject.put("maxTerms", maxTerms); jsonObject.put("showAssetCount", showAssetCount); return jsonObject; } @Override public String getLabel() { return "any-tag"; } @Override public String getTitle() { return "tag"; } @Override @Reference( target = "(osgi.web.symbolicname=com.liferay.portal.search.web)", unbind = "-" ) public void setServletContext(ServletContext servletContext) { super.setServletContext(servletContext); } @Override protected FacetFactory getFacetFactory() { return multiValueFacetFactory; } @Reference protected MultiValueFacetFactory multiValueFacetFactory; }