You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2015/03/26 16:29:38 UTC

svn commit: r1669354 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/test/org/apache/solr/request/TestMacros.java

Author: yonik
Date: Thu Mar 26 15:29:38 2015
New Revision: 1669354

URL: http://svn.apache.org/r1669354
Log:
SOLR-7212: Parameter substitution / macro expansion across entire request

Added:
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/request/TestMacros.java   (with props)
Modified:
    lucene/dev/trunk/solr/CHANGES.txt

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1669354&r1=1669353&r2=1669354&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Thu Mar 26 15:29:38 2015
@@ -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
 ----------------------

Added: lucene/dev/trunk/solr/core/src/test/org/apache/solr/request/TestMacros.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/request/TestMacros.java?rev=1669354&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/request/TestMacros.java (added)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/request/TestMacros.java Thu Mar 26 15:29:38 2015
@@ -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'}]"
+    );
+
+  }
+
+}