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
This commit is contained in:
Yonik Seeley 2010-09-09 00:00:40 +00:00
parent d105271ce9
commit f60c6dab5b
4 changed files with 34 additions and 3 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -214,6 +214,31 @@ public class QueryParsing {
}
}
public static String encodeLocalParamVal(String val) {
int len = val.length();
int i;
for (i=0; i<len; i++) {
char ch = val.charAt(i);
if (Character.isWhitespace(ch) || ch=='}') break;
}
if (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<len; i++) {
char ch = val.charAt(i);
if (ch=='\'') {
sb.append('\\');
}
sb.append(ch);
}
sb.append('\'');
return sb.toString();
}
/**
* "foo" returns null
* "{!prefix f=myfield}yes" returns type="prefix",f="myfield",v="yes"

View File

@ -177,7 +177,7 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {
handle.put("facet_fields", SKIPVAL);
query("q","*:*", "rows",0, "facet","true", "facet.field",t1,"facet.limit",5, "facet.shard.limit",5);
// check a complex key name
query("q","*:*", "rows",0, "facet","true", "facet.field","{!key=a/b/c}"+t1,"facet.limit",5, "facet.shard.limit",5);
query("q","*:*", "rows",0, "facet","true", "facet.field","{!key='a b/c \\' \\} foo'}"+t1,"facet.limit",5, "facet.shard.limit",5);
handle.remove("facet_fields");