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 java.util.ArrayList; 031import java.util.Collection; 032import java.util.List; 033 034import org.apache.commons.lang3.StringUtils; 035 036/** 037 * Configuration that is common for all facets. Used as base class for special facet configurations, e.g. for the field facet configuration. 038 */ 039public class CmsSearchConfigurationFacet implements I_CmsSearchConfigurationFacet { 040 041 /** The minimal number of hits required to add an entry to a facet. */ 042 protected Integer m_minCount; 043 /** A name used to identify the facet when showing it in the search form. */ 044 protected String m_name; 045 /** A label that can be displayed in the form, e.g., at top of the facet. */ 046 protected String m_label; 047 /** The sorting of facet entries. */ 048 protected List<String> m_preselection; 049 /** A flag, indicating if facet filter queries should be concatenated by AND. */ 050 protected boolean m_isAndFacet; 051 /** A flag, indicating if checked entries from other facets should influence the facet or not. */ 052 protected boolean m_ignoreFacetFilters; 053 /** Tags of filter-queries that should not be applied to the facet. */ 054 protected String m_ignoreTags; 055 056 /** The constructor setting all configuration options. 057 * @param minCount The minimal number of hits required to add an entry to a facet. 058 * @param label A label that can be displayed in the form, e.g., at top of the facet. 059 * @param name An optional name for the facet 060 * @param isAndFacet If set to true, the facets filters for results containing all checked entries. Otherwise it filters for results containing at least one checked entry. 061 * @param preselection A list with entries that should be preselected in the facet, when the search page is called the first time. 062 * @param ignoreFiltersFromFacets A flag, indicating if filters from other facets should be ignored or not. 063 */ 064 public CmsSearchConfigurationFacet( 065 final Integer minCount, 066 final String label, 067 final String name, 068 final Boolean isAndFacet, 069 final List<String> preselection, 070 final Boolean ignoreFiltersFromFacets) { 071 072 m_minCount = minCount; 073 m_label = label == null ? name : label; 074 if (isAndFacet != null) { 075 m_isAndFacet = isAndFacet.booleanValue(); 076 } 077 m_name = name; 078 m_preselection = preselection == null ? new ArrayList<String>() : preselection; 079 m_ignoreFacetFilters = ignoreFiltersFromFacets == null ? false : ignoreFiltersFromFacets.booleanValue(); 080 m_ignoreTags = getName(); 081 } 082 083 /** 084 * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacet#getIgnoreAllFacetFilters() 085 */ 086 public boolean getIgnoreAllFacetFilters() { 087 088 return m_ignoreFacetFilters; 089 } 090 091 /** 092 * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacet#getIgnoreMaxParamKey() 093 */ 094 public String getIgnoreMaxParamKey() { 095 096 return getParamKey() + "_ignoremax"; 097 } 098 099 /** 100 * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacet#getIgnoreTags() 101 */ 102 public String getIgnoreTags() { 103 104 return m_ignoreTags; 105 } 106 107 /** 108 * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacet#getIsAndFacet() 109 */ 110 public boolean getIsAndFacet() { 111 112 return m_isAndFacet; 113 } 114 115 /** 116 * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacet#getLabel() 117 */ 118 @Override 119 public String getLabel() { 120 121 return m_label; 122 } 123 124 /** 125 * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacet#getMinCount() 126 */ 127 @Override 128 public Integer getMinCount() { 129 130 return m_minCount; 131 } 132 133 /** 134 * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacet#getName() 135 */ 136 @Override 137 public String getName() { 138 139 return m_name; 140 } 141 142 /** 143 * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacet#getParamKey() 144 */ 145 @Override 146 public String getParamKey() { 147 148 return "facet_" + getName(); 149 } 150 151 /** 152 * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacet#getPreSelection() 153 */ 154 public List<String> getPreSelection() { 155 156 return m_preselection; 157 } 158 159 /** 160 * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacet#propagateAllFacetNames(java.util.Collection) 161 */ 162 public void propagateAllFacetNames(Collection<String> names) { 163 164 if (m_ignoreFacetFilters) { 165 m_ignoreTags = StringUtils.join(names, ',') + ",q"; 166 } 167 } 168 169}