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