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 if (null == query.getParams("facet")) { 075 query.set("facet", "true"); 076 } 077 final Iterator<I_CmsSearchControllerFacetRange> it = m_rangeFacets.values().iterator(); 078 it.next().addQueryParts(query, cms); 079 while (it.hasNext()) { 080 it.next().addQueryParts(query, cms); 081 } 082 } 083 } 084 085 /** 086 * @see org.opencms.jsp.search.controller.I_CmsSearchControllerFacetsRange#getRangeFacetController() 087 */ 088 @Override 089 public Map<String, I_CmsSearchControllerFacetRange> getRangeFacetController() { 090 091 return m_rangeFacets; 092 } 093 094 /** 095 * @see org.opencms.jsp.search.controller.I_CmsSearchControllerFacetsRange#getRangeFacetControllers() 096 */ 097 @Override 098 public Collection<I_CmsSearchControllerFacetRange> getRangeFacetControllers() { 099 100 return m_rangeFacets.values(); 101 } 102 103 /** 104 * @see org.opencms.jsp.search.controller.I_CmsSearchController#updateForQueryChange() 105 */ 106 @Override 107 public void updateForQueryChange() { 108 109 for (final I_CmsSearchControllerFacetRange controller : m_rangeFacets.values()) { 110 controller.updateForQueryChange(); 111 } 112 113 } 114 115 /** 116 * @see org.opencms.jsp.search.controller.I_CmsSearchController#updateFromRequestParameters(java.util.Map, boolean) 117 */ 118 @Override 119 public void updateFromRequestParameters(final Map<String, String[]> parameters, boolean isReloaded) { 120 121 for (final I_CmsSearchControllerFacetRange controller : m_rangeFacets.values()) { 122 controller.updateFromRequestParameters(parameters, isReloaded); 123 } 124 125 } 126 127}