SOLR-7212: Parameter substitution / macro expansion across entire request

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1669354 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2015-03-26 15:29:38 +00:00
parent 845c7c3a5d
commit f2874dd9d3
2 changed files with 98 additions and 1 deletions

View File

@ -214,7 +214,13 @@ New Features
* SOLR-1387: Add facet.contains and facet.contains.ignoreCase options (Tom Winch
via Alan Woodward)
* SOLR-7082: Streaming Aggregation for SolrCloud (Joel bernstein, Yonik Seely)
* SOLR-7082: Streaming Aggregation for SolrCloud (Joel bernstein, Yonik Seeley)
* SOLR-7212: Parameter substitution / macro expansion across entire request.
Substitution can contain further expansions and default values are supported.
Example: q=price:[ ${low:0} TO ${high} ]&low=100&high=200
(yonik)
Bug Fixes
----------------------

View File

@ -0,0 +1,91 @@
package org.apache.solr.request.macro;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.solr.SolrTestCaseJ4;
import org.junit.BeforeClass;
import org.junit.Test;
public class TestMacros extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeTests() throws Exception {
initCore("solrconfig-tlog.xml","schema_latest.xml");
}
@Test
public void testMacros() throws Exception {
assertU(add(doc("id", "1", "val_s", "aaa", "val_i","123")));
assertU(add(doc("id", "2", "val_s", "bbb", "val_i","456")));
assertU(commit());
assertJQ(req("fl","id", "q", "id:${id}", "id","1")
, "/response/docs==[{'id':'1'}]"
);
assertJQ(req("fl","id", "q", "${idquery}", "idquery","id:1")
, "/response/docs==[{'id':'1'}]"
);
assertJQ(req("fl","id", "q", "${fname}:${fval}", "fname","id", "fval","2")
, "/response/docs==[{'id':'2'}]"
);
// test macro expansion in keys...
assertJQ(req("fl","id", "q", "{!term f=$fieldparam v=$valueparam}", "field${p}","val_s", "value${p}", "aaa", "p","param", "echoParams","ALL")
, "/response/docs==[{'id':'1'}]"
);
// test disabling expansion
assertJQ(req("fl","id", "q", "id:\"${id}\"", "id","1", "expandMacros","false")
, "/response/docs==[]"
);
// test multiple levels in values
assertJQ(req("fl","id", "q", "${idquery}", "idquery","${a}${b}", "a","val${fieldpostfix}:", "b","${fieldval}", "fieldpostfix","_s", "fieldval","bbb")
, "/response/docs==[{'id':'2'}]"
);
// test defaults
assertJQ(req("fl","id", "q", "val_s:${val:aaa}")
, "/response/docs==[{'id':'1'}]"
);
// test defaults with value present
assertJQ(req("fl","id", "q", "val_s:${val:aaa}", "val","bbb")
, "/response/docs==[{'id':'2'}]"
);
// test zero length default value
assertJQ(req("fl","id", "q", "val_s:${missing:}aaa")
, "/response/docs==[{'id':'1'}]"
);
// test missing value
assertJQ(req("fl","id", "q", "val_s:${missing}aaa")
, "/response/docs==[{'id':'1'}]"
);
}
}