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