001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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 m_config.getParams().entrySet().stream().forEach( 069 (Map.Entry<String, String> e) -> query.set("hl." + e.getKey(), e.getValue())); 070 } 071 072 /** 073 * @see org.opencms.jsp.search.controller.I_CmsSearchControllerHighlighting#getConfig() 074 */ 075 @Override 076 public I_CmsSearchConfigurationHighlighting getConfig() { 077 078 return m_config; 079 } 080 081 /** 082 * @see org.opencms.jsp.search.controller.I_CmsSearchController#updateForQueryChange() 083 */ 084 @Override 085 public void updateForQueryChange() { 086 087 // Here's nothing to do, since highlighting has no state. 088 089 } 090 091 /** 092 * @see org.opencms.jsp.search.controller.I_CmsSearchController#updateFromRequestParameters(java.util.Map, boolean) 093 */ 094 @Override 095 public void updateFromRequestParameters(final Map<String, String[]> parameters, boolean isReloaded) { 096 097 // Here's nothing to do, since highlighting has no state. 098 099 } 100 101}