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