Permalink
Browse files

Support scalar values in facet initialization parameters.

  • Loading branch information...
Baoqiu Cui
Baoqiu Cui committed May 4, 2012
1 parent af7b5d5 commit 1a56532987e3e531a317bc36ad1b96927329dc35
@@ -321,6 +321,16 @@ else if (selections instanceof JSONObject)
JSONObject jsonParamValues = jsonParams.getJSONObject(paramName);
String type = jsonParamValues.optString(RequestConverter2.FACETINIT_TYPE, RequestConverter2.FACETINIT_TYPE_STRING);
JSONArray jsonValues = jsonParamValues.optJSONArray(RequestConverter2.FACETINIT_VALUES);
+ if (jsonValues == null)
+ {
+ // Accept scalar values here too. This is useful in
+ // supporting variable substitutions.
+ Object value = jsonParamValues.opt(RequestConverter2.FACETINIT_VALUES);
+ if (value != null)
+ {
+ jsonValues = new JSONArray().put(value);
+ }
+ }
if (jsonValues != null)
{
if (type.equals(RequestConverter2.FACETINIT_TYPE_INT))
@@ -282,6 +282,7 @@ public void testSelectionTerms() throws Exception
JSONObject res = search(new JSONObject(req));
assertEquals("numhits is wrong", 4483, res.getInt("numhits"));
}
+
public void testSelectionDynamicTimeRangeJson() throws Exception
{
logger.info("executing test case Selection terms");
@@ -293,6 +294,18 @@ public void testSelectionDynamicTimeRangeJson() throws Exception
assertEquals("numhits is wrong", 12990, res.getInt("numhits"));
}
+ public void testSelectionDynamicTimeRangeJson2() throws Exception
+ {
+ // Test scalar values in facet init parameters
+ logger.info("executing test case Selection terms");
+ String req = "{\"selections\":[{\"term\":{\"timeRange\":{\"value\":\"000000013\"}}}]" +
+ ", \"facetInit\":{ \"timeRange\":{\"time\" :{ \"type\" : \"long\",\"values\" : 15000 }}}" +
+ "}";
+ System.out.println(req);
+ JSONObject res = search(new JSONObject(req));
+ assertEquals("numhits is wrong", 12990, res.getInt("numhits"));
+ }
+
public void testSelectionRange() throws Exception
{
//2000 1548;

0 comments on commit 1a56532

Please sign in to comment.