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.controller;
029
030import org.opencms.file.CmsObject;
031import org.opencms.jsp.search.config.I_CmsSearchConfigurationHighlighting;
032import org.opencms.search.solr.CmsSolrQuery;
033
034import java.util.Map;
035
036/** Controller for highlighting options. */
037public class CmsSearchControllerHighlighting implements I_CmsSearchControllerHighlighting {
038
039    /** The highlighting configuration. */
040    private final I_CmsSearchConfigurationHighlighting m_config;
041
042    /** Constructor taking a highlighting configuration.
043     * @param config The highlighting configuration.
044     */
045    public CmsSearchControllerHighlighting(final I_CmsSearchConfigurationHighlighting config) {
046
047        m_config = config;
048
049    }
050
051    /**
052     * @see org.opencms.jsp.search.controller.I_CmsSearchController#addParametersForCurrentState(java.util.Map)
053     */
054    @Override
055    public void addParametersForCurrentState(final Map<String, String[]> parameters) {
056
057        // Here's nothing to do, since highlighting has no state.
058
059    }
060
061    /**
062     * @see org.opencms.jsp.search.controller.I_CmsSearchController#addQueryParts(CmsSolrQuery, CmsObject)
063     */
064    @Override
065    public void addQueryParts(CmsSolrQuery query, CmsObject cms) {
066
067        query.set("hl", "true");
068        query.set("hl.fl", m_config.getHightlightField());
069        if (m_config.getSnippetsCount() != null) {
070            query.set("hl.snippets", m_config.getSnippetsCount().toString());
071        }
072        if (m_config.getFragSize() != null) {
073            query.set("hl.fragsize", m_config.getFragSize().toString());
074        }
075        if (m_config.getAlternateHighlightField() != null) {
076            query.set("hl.alternateField", m_config.getAlternateHighlightField());
077        }
078        if (m_config.getMaxAlternateHighlightFieldLength() != null) {
079            query.set("hl.maxAlternateFieldLength", m_config.getMaxAlternateHighlightFieldLength().toString());
080        }
081        if (m_config.getSimplePre() != null) {
082            query.set("hl.simple.pre", m_config.getSimplePre());
083        }
084        if (m_config.getSimplePost() != null) {
085            query.set("hl.simple.post", m_config.getSimplePost());
086        }
087        if (m_config.getFormatter() != null) {
088            query.set("hl.formatter", m_config.getFormatter());
089        }
090        if (m_config.getFragmenter() != null) {
091            query.set("hl.fragmenter", m_config.getFragmenter());
092        }
093        if (m_config.getUseFastVectorHighlighting() != null) {
094            query.set("hl.useFastVectorHighlighting", m_config.getUseFastVectorHighlighting().toString());
095        }
096    }
097
098    /**
099     * @see org.opencms.jsp.search.controller.I_CmsSearchControllerHighlighting#getConfig()
100     */
101    @Override
102    public I_CmsSearchConfigurationHighlighting getConfig() {
103
104        return m_config;
105    }
106
107    /**
108     * @see org.opencms.jsp.search.controller.I_CmsSearchController#updateForQueryChange()
109     */
110    @Override
111    public void updateForQueryChange() {
112
113        // Here's nothing to do, since highlighting has no state.
114
115    }
116
117    /**
118     * @see org.opencms.jsp.search.controller.I_CmsSearchController#updateFromRequestParameters(java.util.Map, boolean)
119     */
120    @Override
121    public void updateFromRequestParameters(final Map<String, String[]> parameters, boolean isReloaded) {
122
123        // Here's nothing to do, since highlighting has no state.
124
125    }
126
127}