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.parser; 029 030import org.opencms.jsp.search.config.CmsSearchConfigurationCommon; 031import org.opencms.jsp.search.config.I_CmsSearchConfiguration; 032import org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon; 033import org.opencms.jsp.search.config.I_CmsSearchConfigurationDidYouMean; 034import org.opencms.jsp.search.config.I_CmsSearchConfigurationFacetField; 035import org.opencms.jsp.search.config.I_CmsSearchConfigurationFacetQuery; 036import org.opencms.jsp.search.config.I_CmsSearchConfigurationFacetRange; 037import org.opencms.jsp.search.config.I_CmsSearchConfigurationHighlighting; 038import org.opencms.jsp.search.config.I_CmsSearchConfigurationPagination; 039import org.opencms.jsp.search.config.I_CmsSearchConfigurationSorting; 040import org.opencms.main.CmsLog; 041 042import java.util.Collections; 043import java.util.Map; 044 045import org.apache.commons.logging.Log; 046 047/** Search configuration parser reading a configuration containing a plain Solr query. 048 * Only fl might be added additionally. */ 049public class CmsPlainQuerySearchConfigurationParser implements I_CmsSearchConfigurationParser { 050 051 /** Logger for the class. */ 052 protected static final Log LOG = CmsLog.getLog(CmsPlainQuerySearchConfigurationParser.class); 053 054 /** The default return fields. */ 055 private static final String DEFAULT_FL = "id,path"; 056 057 /** The whole query string. */ 058 protected String m_queryString; 059 060 /** The optional base configuration that should be changed by the JSON configuration. */ 061 private I_CmsSearchConfiguration m_baseConfig; 062 063 /** Constructor taking the JSON as String. 064 * @param query The query that is passed to Solr. 065 */ 066 public CmsPlainQuerySearchConfigurationParser(String query) { 067 068 this(query, null); 069 } 070 071 /** Constructor taking the JSON as String. 072 * @param query The query that is passed to Solr (additional Solr params). 073 * @param baseConfig A base configuration that is adjusted by the JSON configuration string. 074 */ 075 public CmsPlainQuerySearchConfigurationParser(String query, I_CmsSearchConfiguration baseConfig) { 076 077 if ((null != query) && !(query.startsWith("fl=") || query.contains("&fl="))) { 078 query = query + "&fl=" + DEFAULT_FL; 079 } 080 m_queryString = query; 081 m_baseConfig = baseConfig; 082 083 } 084 085 /** 086 * @see org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser#parseCommon() 087 */ 088 public I_CmsSearchConfigurationCommon parseCommon() { 089 090 return new CmsSearchConfigurationCommon( 091 null, 092 null, 093 null, 094 null, 095 Boolean.TRUE, 096 Boolean.TRUE, 097 null, 098 null, 099 null, 100 m_queryString, 101 null, 102 null, 103 null); 104 } 105 106 /** 107 * @see org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser#parseDidYouMean() 108 */ 109 public I_CmsSearchConfigurationDidYouMean parseDidYouMean() { 110 111 return null != m_baseConfig ? m_baseConfig.getDidYouMeanConfig() : null; 112 } 113 114 /** 115 * @see org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser#parseFieldFacets() 116 */ 117 public Map<String, I_CmsSearchConfigurationFacetField> parseFieldFacets() { 118 119 return null != m_baseConfig ? m_baseConfig.getFieldFacetConfigs() : Collections.emptyMap(); 120 } 121 122 /** 123 * @see org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser#parseHighlighter() 124 */ 125 public I_CmsSearchConfigurationHighlighting parseHighlighter() { 126 127 return null != m_baseConfig ? m_baseConfig.getHighlighterConfig() : null; 128 } 129 130 /** 131 * @see org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser#parsePagination() 132 */ 133 public I_CmsSearchConfigurationPagination parsePagination() { 134 135 return null != m_baseConfig ? m_baseConfig.getPaginationConfig() : null; 136 } 137 138 /** 139 * @see org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser#parseQueryFacet() 140 */ 141 public I_CmsSearchConfigurationFacetQuery parseQueryFacet() { 142 143 return null != m_baseConfig ? m_baseConfig.getQueryFacetConfig() : null; 144 } 145 146 /** 147 * @see org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser#parseRangeFacets() 148 */ 149 public Map<String, I_CmsSearchConfigurationFacetRange> parseRangeFacets() { 150 151 return null != m_baseConfig ? m_baseConfig.getRangeFacetConfigs() : Collections.emptyMap(); 152 } 153 154 /** 155 * @see org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser#parseSorting() 156 */ 157 public I_CmsSearchConfigurationSorting parseSorting() { 158 159 return null != m_baseConfig ? m_baseConfig.getSortConfig() : null; 160 } 161}