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.config; 029 030import org.opencms.file.CmsObject; 031import org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser; 032 033import java.util.ArrayList; 034import java.util.Collection; 035import java.util.HashMap; 036import java.util.Map; 037 038/** 039 * The main search configuration. It's a collection of all the different parts of a search configuration. 040 */ 041public class CmsSearchConfiguration implements I_CmsSearchConfiguration { 042 043 /** The general search configuration. */ 044 private final I_CmsSearchConfigurationCommon m_general; 045 046 /** The Geo filter configuration. */ 047 private final I_CmsSearchConfigurationGeoFilter m_geoFilter; 048 049 /** The configuration for pagination. */ 050 private final I_CmsSearchConfigurationPagination m_pagination; 051 052 /** The configurations for field facets. */ 053 private final Map<String, I_CmsSearchConfigurationFacetField> m_fieldFacets; 054 055 /** The configurations for range facets. */ 056 private final Map<String, I_CmsSearchConfigurationFacetRange> m_rangeFacets; 057 058 /** The configuration for query facet. */ 059 private final I_CmsSearchConfigurationFacetQuery m_queryFacet; 060 061 /** The sorting configuration. */ 062 private final I_CmsSearchConfigurationSorting m_sorting; 063 064 /** The highlighting configuration. */ 065 private final I_CmsSearchConfigurationHighlighting m_highlighting; 066 067 /** The "Did you mean ...?" configuration. */ 068 private final I_CmsSearchConfigurationDidYouMean m_didYouMean; 069 070 /** Constructor to initialize the configuration object via a configuration parser. 071 * @param parser The configuration parser that's used to read the configuration. 072 * @param cms The current context. 073 */ 074 public CmsSearchConfiguration(final I_CmsSearchConfigurationParser parser, CmsObject cms) { 075 076 m_general = parser.parseCommon(cms); 077 m_geoFilter = parser.parseGeoFilter(); 078 m_pagination = parser.parsePagination(); 079 m_sorting = parser.parseSorting(); 080 m_fieldFacets = new HashMap<>(parser.parseFieldFacets()); 081 m_rangeFacets = new HashMap<>(parser.parseRangeFacets()); 082 m_queryFacet = parser.parseQueryFacet(); 083 m_highlighting = parser.parseHighlighter(); 084 m_didYouMean = parser.parseDidYouMean(); 085 086 propagateFacetNames(); 087 088 } 089 090 /** 091 * @see org.opencms.jsp.search.config.I_CmsSearchConfiguration#extend(org.opencms.jsp.search.config.I_CmsSearchConfiguration) 092 */ 093 @Override 094 public void extend(I_CmsSearchConfiguration extensionConfig) { 095 096 m_general.extend(extensionConfig.getGeneralConfig()); 097 m_fieldFacets.putAll(extensionConfig.getFieldFacetConfigs()); 098 m_rangeFacets.putAll(extensionConfig.getRangeFacetConfigs()); 099 propagateFacetNames(); 100 101 } 102 103 /** 104 * @see org.opencms.jsp.search.config.I_CmsSearchConfiguration#getDidYouMeanConfig() 105 */ 106 @Override 107 public I_CmsSearchConfigurationDidYouMean getDidYouMeanConfig() { 108 109 return m_didYouMean; 110 } 111 112 /** 113 * @see org.opencms.jsp.search.config.I_CmsSearchConfiguration#getFieldFacetConfigs() 114 */ 115 @Override 116 public Map<String, I_CmsSearchConfigurationFacetField> getFieldFacetConfigs() { 117 118 return m_fieldFacets; 119 } 120 121 /** 122 * @see org.opencms.jsp.search.config.I_CmsSearchConfiguration#getGeneralConfig() 123 */ 124 @Override 125 public I_CmsSearchConfigurationCommon getGeneralConfig() { 126 127 return m_general; 128 } 129 130 /** 131 * @see org.opencms.jsp.search.config.I_CmsSearchConfiguration#getGeoFilterConfig() 132 */ 133 @Override 134 public I_CmsSearchConfigurationGeoFilter getGeoFilterConfig() { 135 136 return m_geoFilter; 137 } 138 139 /** 140 * @see org.opencms.jsp.search.config.I_CmsSearchConfiguration#getHighlighterConfig() 141 */ 142 @Override 143 public I_CmsSearchConfigurationHighlighting getHighlighterConfig() { 144 145 return m_highlighting; 146 } 147 148 /** 149 * @see org.opencms.jsp.search.config.I_CmsSearchConfiguration#getPaginationConfig() 150 */ 151 @Override 152 public I_CmsSearchConfigurationPagination getPaginationConfig() { 153 154 return m_pagination; 155 } 156 157 /** 158 * @see org.opencms.jsp.search.config.I_CmsSearchConfiguration#getQueryFacetConfig() 159 */ 160 @Override 161 public I_CmsSearchConfigurationFacetQuery getQueryFacetConfig() { 162 163 return m_queryFacet; 164 } 165 166 /** 167 * @see org.opencms.jsp.search.config.I_CmsSearchConfiguration#getRangeFacetConfigs() 168 */ 169 public Map<String, I_CmsSearchConfigurationFacetRange> getRangeFacetConfigs() { 170 171 return m_rangeFacets; 172 } 173 174 /** 175 * @see org.opencms.jsp.search.config.I_CmsSearchConfiguration#getSortConfig() 176 */ 177 @Override 178 public I_CmsSearchConfigurationSorting getSortConfig() { 179 180 return m_sorting; 181 } 182 183 /** 184 * Propagates the names of all facets to each single facet. 185 */ 186 private void propagateFacetNames() { 187 188 // collect all names and configurations 189 Collection<String> facetNames = new ArrayList<String>(); 190 Collection<I_CmsSearchConfigurationFacet> facetConfigs = new ArrayList<I_CmsSearchConfigurationFacet>(); 191 facetNames.addAll(m_fieldFacets.keySet()); 192 facetConfigs.addAll(m_fieldFacets.values()); 193 facetNames.addAll(m_rangeFacets.keySet()); 194 facetConfigs.addAll(m_rangeFacets.values()); 195 if (null != m_queryFacet) { 196 facetNames.add(m_queryFacet.getName()); 197 facetConfigs.add(m_queryFacet); 198 } 199 200 // propagate all names 201 for (I_CmsSearchConfigurationFacet facetConfig : facetConfigs) { 202 facetConfig.propagateAllFacetNames(facetNames); 203 } 204 } 205}