001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.jsp.search.controller; 029 030import org.opencms.file.CmsObject; 031import org.opencms.jsp.search.config.I_CmsSearchConfigurationFacetRange; 032import org.opencms.search.solr.CmsSolrQuery; 033 034import java.util.Collection; 035import java.util.Iterator; 036import java.util.LinkedHashMap; 037import java.util.Map; 038 039/** Search controller as aggregation of all single field facet controllers. */ 040public class CmsSearchControllerFacetsRange implements I_CmsSearchControllerFacetsRange { 041 042 /** Controllers of the single field facets with the facet's name as key. */ 043 Map<String, I_CmsSearchControllerFacetRange> m_rangeFacets; 044 045 /** Constructor taking the list of field facet controllers that are aggregated. 046 * @param configs The controllers for single field facets. 047 */ 048 public CmsSearchControllerFacetsRange(final Map<String, I_CmsSearchConfigurationFacetRange> configs) { 049 050 m_rangeFacets = new LinkedHashMap<String, I_CmsSearchControllerFacetRange>(); 051 for (final String name : configs.keySet()) { 052 m_rangeFacets.put(name, new CmsSearchControllerFacetRange(configs.get(name))); 053 } 054 } 055 056 /** 057 * @see org.opencms.jsp.search.controller.I_CmsSearchController#addParametersForCurrentState(java.util.Map) 058 */ 059 @Override 060 public void addParametersForCurrentState(final Map<String, String[]> parameters) { 061 062 for (final I_CmsSearchControllerFacetRange controller : m_rangeFacets.values()) { 063 controller.addParametersForCurrentState(parameters); 064 } 065 } 066 067 /** 068 * @see org.opencms.jsp.search.controller.I_CmsSearchController#addQueryParts(CmsSolrQuery, CmsObject) 069 */ 070 @Override 071 public void addQueryParts(CmsSolrQuery query, CmsObject cms) { 072 073 if (!m_rangeFacets.isEmpty()) { 074 query.set("facet", "true"); 075 final Iterator<I_CmsSearchControllerFacetRange> it = m_rangeFacets.values().iterator(); 076 it.next().addQueryParts(query, cms); 077 while (it.hasNext()) { 078 it.next().addQueryParts(query, cms); 079 } 080 } 081 } 082 083 /** 084 * @see org.opencms.jsp.search.controller.I_CmsSearchControllerFacetsRange#getRangeFacetController() 085 */ 086 @Override 087 public Map<String, I_CmsSearchControllerFacetRange> getRangeFacetController() { 088 089 return m_rangeFacets; 090 } 091 092 /** 093 * @see org.opencms.jsp.search.controller.I_CmsSearchControllerFacetsRange#getRangeFacetControllers() 094 */ 095 @Override 096 public Collection<I_CmsSearchControllerFacetRange> getRangeFacetControllers() { 097 098 return m_rangeFacets.values(); 099 } 100 101 /** 102 * @see org.opencms.jsp.search.controller.I_CmsSearchController#updateForQueryChange() 103 */ 104 @Override 105 public void updateForQueryChange() { 106 107 for (final I_CmsSearchControllerFacetRange controller : m_rangeFacets.values()) { 108 controller.updateForQueryChange(); 109 } 110 111 } 112 113 /** 114 * @see org.opencms.jsp.search.controller.I_CmsSearchController#updateFromRequestParameters(java.util.Map, boolean) 115 */ 116 @Override 117 public void updateFromRequestParameters(final Map<String, String[]> parameters, boolean isReloaded) { 118 119 for (final I_CmsSearchControllerFacetRange controller : m_rangeFacets.values()) { 120 controller.updateFromRequestParameters(parameters, isReloaded); 121 } 122 123 } 124 125}