From f60c6dab5b64aeb13eb2349e12142071f497085a Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Thu, 9 Sep 2010 00:00:40 +0000 Subject: [PATCH] SOLR-2110: properly escape/encode local params in distrib faceting git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@995286 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 4 +++ .../handler/component/FacetComponent.java | 6 +++-- .../org/apache/solr/search/QueryParsing.java | 25 +++++++++++++++++++ .../apache/solr/TestDistributedSearch.java | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index adffaaf5ed4..27b96967f96 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -466,6 +466,10 @@ Bug Fixes prevent an exception in one facet command from affecting another facet command. (yonik) +* SOLR-2110: Remove the restriction on names for local params + substitution/dereferencing. Properly encode local params in + distributed faceting. (yonik) + * SOLR-2114: Fixed parsing error in hsin function. The function signature has changed slightly. (gsingers) diff --git a/solr/src/java/org/apache/solr/handler/component/FacetComponent.java b/solr/src/java/org/apache/solr/handler/component/FacetComponent.java index 339f5997356..cb5bb61a830 100644 --- a/solr/src/java/org/apache/solr/handler/component/FacetComponent.java +++ b/solr/src/java/org/apache/solr/handler/component/FacetComponent.java @@ -106,10 +106,12 @@ public class FacetComponent extends SearchComponent String facetCommand; // add terms into the original facet.field command // do it via parameter reference to avoid another layer of encoding. + + String termsKeyEncoded = QueryParsing.encodeLocalParamVal(termsKey); if (dff.localParams != null) { - facetCommand = commandPrefix+termsKey + " " + dff.facetStr.substring(2); + facetCommand = commandPrefix+termsKeyEncoded + " " + dff.facetStr.substring(2); } else { - facetCommand = commandPrefix+termsKey+'}'+dff.field; + facetCommand = commandPrefix+termsKeyEncoded+'}'+dff.field; } if (refinements == null) { diff --git a/solr/src/java/org/apache/solr/search/QueryParsing.java b/solr/src/java/org/apache/solr/search/QueryParsing.java index e34de87c935..f6398e16729 100644 --- a/solr/src/java/org/apache/solr/search/QueryParsing.java +++ b/solr/src/java/org/apache/solr/search/QueryParsing.java @@ -214,6 +214,31 @@ public class QueryParsing { } } + public static String encodeLocalParamVal(String val) { + int len = val.length(); + int i; + for (i=0; i=len) return val; + + // We need to enclose in quotes... but now we need to escape + StringBuilder sb = new StringBuilder(val.length() + 4); + sb.append('\''); + for (i=0; i