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.HashMap;
031import java.util.Map;
032
033/**
034 * Search configuration for common parameters as the query parameter etc.
035 */
036public class CmsSearchConfigurationCommon implements I_CmsSearchConfigurationCommon {
037
038    /** The query request parameter. */
039    private final String m_queryParam;
040    /** The request parameter for the last query. */
041    private final String m_lastQueryParam;
042    /** A flag, indicating if special query characters should be escaped in the query string. */
043    private final boolean m_escapeQueryChars;
044    /** The request parameter send to indicate that this is not the first load of the search form. */
045    private final String m_reloadedParam;
046    /** A modifier for the search query. */
047    private final String m_queryModifier;
048    /** A flag, indicating if the empty query should be interpreted as "*:*" or if no search should be performed. */
049    private final boolean m_searchForEmptyQuery;
050    /** A flag, indicating if the query params should be used at all (or if the query is fixed). */
051    private final boolean m_ignoreQuery;
052    /** The Solr index to use for the query (specified by it's name). */
053    private final String m_solrIndex;
054    /** The Solr core to use for the query (specified by it's name). */
055    private final String m_solrCore;
056    /** Extra parameters given to Solr, specified like "p1=v1&p2=v2". */
057    private final String m_extraSolrParams;
058    /** Additional request parameters mapped to their Solr query parts. */
059    private final Map<String, String> m_additionalParameters;
060    /** Flag, indicating if the release date should be ignored. */
061    private boolean m_ignoreReleaseDate;
062    /** Flag, indicating if the expiration date should be ignored. */
063    private boolean m_ignoreExpirationDate;
064
065    /** Constructor for the common search configuration, where all configuration parameters are provided.
066     * @param queryParam The query request param used by the search form.
067     * @param lastQueryParam The last-query request param used by the search form.
068     * @param escapeQueryChars A flag, indicating if special query characters in the query string should be escaped (default <code>true</code>).
069     * @param reloadedParam The first-call request param used by the search form.
070     * @param seachForEmptyQuery A flag, indicating if the empty query should be interpreted as "*:*" or if no search should be performed.
071     * @param ignoreQuery A flag, indicating if the query param's values should be used for Solr query generation.
072     * @param queryModifier Modifier for the given query string.
073     * @param solrIndex The Solr index that should be used for the search.
074     * @param solrCore The Solr core that should be used for the search.
075     * @param extraSolrParams Extra params that are directly appended to each search query.
076     * @param additionalParameters A map from additional request parameters to Solr query parts.
077     * @param ignoreReleaseDate A flag, indicating if the release date should be ignored.
078     * @param ignoreExpirationDate A flag, indicating if the expiration date should be ignored.
079     */
080    public CmsSearchConfigurationCommon(
081        final String queryParam,
082        final String lastQueryParam,
083        final Boolean escapeQueryChars,
084        final String reloadedParam,
085        final Boolean seachForEmptyQuery,
086        final Boolean ignoreQuery,
087        final String queryModifier,
088        final String solrIndex,
089        final String solrCore,
090        final String extraSolrParams,
091        final Map<String, String> additionalParameters,
092        final Boolean ignoreReleaseDate,
093        final Boolean ignoreExpirationDate) {
094
095        m_queryParam = queryParam;
096        m_lastQueryParam = lastQueryParam;
097        m_escapeQueryChars = escapeQueryChars != null ? escapeQueryChars.booleanValue() : true;
098        m_reloadedParam = reloadedParam;
099        m_searchForEmptyQuery = seachForEmptyQuery != null ? seachForEmptyQuery.booleanValue() : false;
100        m_ignoreQuery = ignoreQuery != null ? ignoreQuery.booleanValue() : false;
101        m_queryModifier = queryModifier;
102        m_solrIndex = solrIndex;
103        m_solrCore = solrCore;
104        m_extraSolrParams = extraSolrParams == null ? "" : extraSolrParams;
105        m_additionalParameters = additionalParameters != null ? additionalParameters : new HashMap<String, String>();
106        m_ignoreReleaseDate = null == ignoreReleaseDate ? false : ignoreReleaseDate.booleanValue();
107        m_ignoreExpirationDate = null == ignoreExpirationDate ? false : ignoreExpirationDate.booleanValue();
108    }
109
110    /**
111     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getAdditionalParameters()
112     */
113    @Override
114    public Map<String, String> getAdditionalParameters() {
115
116        return m_additionalParameters;
117    }
118
119    /**
120     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getEscapeQueryChars()
121     */
122    public boolean getEscapeQueryChars() {
123
124        return m_escapeQueryChars;
125    }
126
127    /**
128     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getExtraSolrParams()
129     */
130    @Override
131    public String getExtraSolrParams() {
132
133        return m_extraSolrParams;
134    }
135
136    /**
137     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getIgnoreExpirationDate()
138     */
139    public boolean getIgnoreExpirationDate() {
140
141        return m_ignoreExpirationDate;
142    }
143
144    /**
145     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getIgnoreQueryParam()
146     */
147    public boolean getIgnoreQueryParam() {
148
149        return m_ignoreQuery;
150    }
151
152    /**
153     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getIgnoreReleaseDate()
154     */
155    public boolean getIgnoreReleaseDate() {
156
157        return m_ignoreReleaseDate;
158    }
159
160    /**
161     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getLastQueryParam()
162     */
163    @Override
164    public String getLastQueryParam() {
165
166        return m_lastQueryParam;
167    }
168
169    /**
170     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getModifiedQuery(java.lang.String)
171     */
172    @Override
173    public String getModifiedQuery(String queryString) {
174
175        if (null != m_queryModifier) {
176            return m_queryModifier.replace("%(query)", queryString);
177        }
178        return queryString;
179    }
180
181    /**
182     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getQueryModifier()
183     */
184    public String getQueryModifier() {
185
186        return m_queryModifier;
187    }
188
189    /**
190     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getQueryParam()
191     */
192    @Override
193    public String getQueryParam() {
194
195        return m_queryParam;
196    }
197
198    /**
199     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getReloadedParam()
200     */
201    public String getReloadedParam() {
202
203        return m_reloadedParam;
204    }
205
206    /**
207     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getSearchForEmptyQueryParam()
208     */
209    @Override
210    public boolean getSearchForEmptyQueryParam() {
211
212        return m_searchForEmptyQuery;
213    }
214
215    /**
216     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getSolrCore()
217     */
218    @Override
219    public String getSolrCore() {
220
221        return m_solrCore;
222    }
223
224    /**
225     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getSolrIndex()
226     */
227    @Override
228    public String getSolrIndex() {
229
230        return m_solrIndex;
231    }
232
233}