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.Collection;
031import java.util.List;
032
033/**
034 * Search configuration special for field facets. Extends @see{org.opencms.jsp.search.config.CmsSearchConfigurationFacet}.
035 */
036public class CmsSearchConfigurationFacetField extends CmsSearchConfigurationFacet
037implements I_CmsSearchConfigurationFacetField {
038
039    /** A prefix, all entries of a facet must start with. */
040    protected String m_prefix = "";
041
042    /** The index field to use for the facet. */
043    protected String m_field;
044
045    /** The maximal number of entries shown in a facet. */
046    protected Integer m_limit;
047
048    /** The sorting of facet entries. */
049    protected SortOrder m_sort;
050
051    /** A modifier for filter queries. */
052    protected String m_fiterQueryModifier;
053
054    /** Constructor directly setting all configuration values.
055     * @param field The index field to use for the facet.
056     * @param name The name of the facet. If <code>null</code> it defaults to the name of the index field.
057     * @param minCount The minimal number of hits that is necessary to add a term to the facet.
058     * @param limit The maximal number of facet entries.
059     * @param prefix A prefix all entries of a facet must have.
060     * @param label The label that can be shown over the facet entries in your search form.
061     * @param order The sorting of the facet entries (either "count", which is default, or "index", which causes alphabetical sorting).
062     * @param filterQueryModifier Modifier for the filter queries when a facet entry is checked. Can contain "%(value)" - what is replaced by the facet entry's value.
063     * @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.
064     * @param preselection The list of facet items that should be preselected for the first search.
065     * @param ignoreFiltersFromAllFacets A flag, indicating if filters from all facets should be ignored or not.
066     * @param excludeTags The tags (keys) of (filter) queries to be not taken into account for the facet. If "ignoreFiltersFromFacets" is true, the according tags for facets and queries will be added.
067     */
068    public CmsSearchConfigurationFacetField(
069        final String field,
070        final String name,
071        final Integer minCount,
072        final Integer limit,
073        final String prefix,
074        final String label,
075        final SortOrder order,
076        final String filterQueryModifier,
077        final Boolean isAndFacet,
078        final List<String> preselection,
079        final Boolean ignoreFiltersFromAllFacets,
080        final Collection<String> excludeTags) {
081
082        super(
083            minCount,
084            label,
085            null != name ? name : field,
086            isAndFacet,
087            preselection,
088            ignoreFiltersFromAllFacets,
089            excludeTags);
090
091        if (prefix != null) {
092            m_prefix = prefix;
093        }
094
095        m_limit = limit;
096        m_sort = order;
097        m_field = field;
098        m_fiterQueryModifier = filterQueryModifier;
099    }
100
101    /**
102     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacetField#getField()
103     */
104    @Override
105    public String getField() {
106
107        return m_field;
108    }
109
110    /**
111     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacetField#getLimit()
112     */
113    @Override
114    public Integer getLimit() {
115
116        return m_limit;
117    }
118
119    /**
120     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacetField#getPrefix()
121     */
122    @Override
123    public String getPrefix() {
124
125        return m_prefix;
126    }
127
128    /**
129     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacetField#getSortOrder()
130     */
131    @Override
132    public SortOrder getSortOrder() {
133
134        return m_sort;
135    }
136
137    /**
138     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationFacetField#modifyFilterQuery(java.lang.String)
139     */
140    @Override
141    public String modifyFilterQuery(final String facetValue) {
142
143        if (m_fiterQueryModifier == null) {
144            return "\"" + facetValue + "\"";
145        }
146        return m_fiterQueryModifier.replace("%(value)", facetValue);
147    }
148
149}