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    /** The maximally returned number of results */
065    private final int m_maxReturnedResults;
066
067    /** Constructor for the common search configuration, where all configuration parameters are provided.
068     * @param queryParam The query request param used by the search form.
069     * @param lastQueryParam The last-query request param used by the search form.
070     * @param escapeQueryChars A flag, indicating if special query characters in the query string should be escaped (default <code>true</code>).
071     * @param reloadedParam The first-call request param used by the search form.
072     * @param seachForEmptyQuery A flag, indicating if the empty query should be interpreted as "*:*" or if no search should be performed.
073     * @param ignoreQuery A flag, indicating if the query param's values should be used for Solr query generation.
074     * @param queryModifier Modifier for the given query string.
075     * @param solrIndex The Solr index that should be used for the search.
076     * @param solrCore The Solr core that should be used for the search.
077     * @param extraSolrParams Extra params that are directly appended to each search query.
078     * @param additionalParameters A map from additional request parameters to Solr query parts.
079     * @param ignoreReleaseDate A flag, indicating if the release date should be ignored.
080     * @param ignoreExpirationDate A flag, indicating if the expiration date should be ignored.
081     * @param maxReturnedResults Number of results maximally to return.
082     *           <code><= 0</code> means that there is no limit.
083     */
084    public CmsSearchConfigurationCommon(
085        final String queryParam,
086        final String lastQueryParam,
087        final Boolean escapeQueryChars,
088        final String reloadedParam,
089        final Boolean seachForEmptyQuery,
090        final Boolean ignoreQuery,
091        final String queryModifier,
092        final String solrIndex,
093        final String solrCore,
094        final String extraSolrParams,
095        final Map<String, String> additionalParameters,
096        final Boolean ignoreReleaseDate,
097        final Boolean ignoreExpirationDate,
098        final int maxReturnedResults) {
099
100        m_queryParam = queryParam;
101        m_lastQueryParam = lastQueryParam;
102        m_escapeQueryChars = escapeQueryChars != null ? escapeQueryChars.booleanValue() : true;
103        m_reloadedParam = reloadedParam;
104        m_searchForEmptyQuery = seachForEmptyQuery != null ? seachForEmptyQuery.booleanValue() : false;
105        m_ignoreQuery = ignoreQuery != null ? ignoreQuery.booleanValue() : false;
106        m_queryModifier = queryModifier;
107        m_solrIndex = solrIndex;
108        m_solrCore = solrCore;
109        m_extraSolrParams = extraSolrParams == null ? "" : extraSolrParams;
110        m_additionalParameters = additionalParameters != null ? additionalParameters : new HashMap<String, String>();
111        m_ignoreReleaseDate = null == ignoreReleaseDate ? false : ignoreReleaseDate.booleanValue();
112        m_ignoreExpirationDate = null == ignoreExpirationDate ? false : ignoreExpirationDate.booleanValue();
113        m_maxReturnedResults = maxReturnedResults;
114    }
115
116    /**
117     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getAdditionalParameters()
118     */
119    @Override
120    public Map<String, String> getAdditionalParameters() {
121
122        return m_additionalParameters;
123    }
124
125    /**
126     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getEscapeQueryChars()
127     */
128    public boolean getEscapeQueryChars() {
129
130        return m_escapeQueryChars;
131    }
132
133    /**
134     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getExtraSolrParams()
135     */
136    @Override
137    public String getExtraSolrParams() {
138
139        return m_extraSolrParams;
140    }
141
142    /**
143     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getIgnoreExpirationDate()
144     */
145    public boolean getIgnoreExpirationDate() {
146
147        return m_ignoreExpirationDate;
148    }
149
150    /**
151     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getIgnoreQueryParam()
152     */
153    public boolean getIgnoreQueryParam() {
154
155        return m_ignoreQuery;
156    }
157
158    /**
159     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getIgnoreReleaseDate()
160     */
161    public boolean getIgnoreReleaseDate() {
162
163        return m_ignoreReleaseDate;
164    }
165
166    /**
167     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getLastQueryParam()
168     */
169    @Override
170    public String getLastQueryParam() {
171
172        return m_lastQueryParam;
173    }
174
175    /**
176     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getMaxReturnedResults()
177     */
178    public int getMaxReturnedResults() {
179
180        return m_maxReturnedResults;
181    }
182
183    /**
184     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getModifiedQuery(java.lang.String)
185     */
186    @Override
187    public String getModifiedQuery(String queryString) {
188
189        if (null != m_queryModifier) {
190            return m_queryModifier.replace("%(query)", queryString);
191        }
192        return queryString;
193    }
194
195    /**
196     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getQueryModifier()
197     */
198    public String getQueryModifier() {
199
200        return m_queryModifier;
201    }
202
203    /**
204     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getQueryParam()
205     */
206    @Override
207    public String getQueryParam() {
208
209        return m_queryParam;
210    }
211
212    /**
213     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getReloadedParam()
214     */
215    public String getReloadedParam() {
216
217        return m_reloadedParam;
218    }
219
220    /**
221     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getSearchForEmptyQueryParam()
222     */
223    @Override
224    public boolean getSearchForEmptyQueryParam() {
225
226        return m_searchForEmptyQuery;
227    }
228
229    /**
230     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getSolrCore()
231     */
232    @Override
233    public String getSolrCore() {
234
235        return m_solrCore;
236    }
237
238    /**
239     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon#getSolrIndex()
240     */
241    @Override
242    public String getSolrIndex() {
243
244        return m_solrIndex;
245    }
246
247}