Skip to content

Commit

Permalink
cms:search / cms:simplesearch / integrated list: Added macros %(query)
Browse files Browse the repository at this point in the history
and %(locale) to the additionalsolrparams as suggested in GitHub issue
#686.

Note that the macros - like the whole additionalsolrparams must be
provided url encoded, i.e. %25%28query%29 and %25%28locale%29.
  • Loading branch information
dSeidel committed Oct 8, 2021
1 parent baf1b36 commit 745bc78
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.opencms.file.CmsObject;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon;
import org.opencms.jsp.search.state.CmsSearchStateCommon;
import org.opencms.jsp.search.state.I_CmsSearchStateCommon;
Expand All @@ -52,6 +53,10 @@ public class CmsSearchControllerCommon implements I_CmsSearchControllerCommon {
private static final String MACRO_VALUE = "value";
/** Site root macro. */
private static final String MACRO_SITE_ROOT = "site_root";
/** Locale macro. */
private static final String MACRO_LOCALE = "locale";
/** Query macro. */
private static final String MACRO_QUERY = "query";
/** Configuration of common search options. */
private final I_CmsSearchConfigurationCommon m_config;
/** State of the common search options. */
Expand Down Expand Up @@ -116,13 +121,18 @@ public void addQueryParts(CmsSolrQuery query, CmsObject cms) {
if ((null != currentSiteRoot) && !currentSiteRoot.endsWith("/")) {
currentSiteRoot = currentSiteRoot + "/";
}
String currentLocale = (null == cms
? CmsLocaleManager.getDefaultLocale()
: cms.getRequestContext().getLocale()).toString();
Map<String, String[]> extraParamsMap = CmsRequestUtil.createParameterMap(
m_config.getExtraSolrParams(),
true,
null);
for (String key : extraParamsMap.keySet()) {
for (String value : Arrays.asList(extraParamsMap.get(key))) {
value = resolveMacro(value, MACRO_SITE_ROOT, currentSiteRoot);
value = resolveMacro(value, MACRO_LOCALE, currentLocale);
value = resolveMacro(value, MACRO_QUERY, queryString);
if (SET_VARIABLES.contains(key)) {
if (key.equals(CommonParams.FL)) {
query.setReturnFields(value);
Expand Down

0 comments on commit 745bc78

Please sign in to comment.