Apache Solr open-source search software
SOLR-13679:Fix default style of [explain] registered in solrconfig.xml
Munendra S N84a62a5d8735
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 99c81b9abaa..d95df054e23 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -143,6 +143,9 @@ Other Changes* SOLR-13659: Refactor CacheConfig to lazily load the the implementation class (noble)+* SOLR-13679: Default style of ExplainDocTransformer registered via solrconfig.xml should be same as default style+ of ExplainDocTransformer registered in defaultFactories (Munendra S N)+================== 8.2.0 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.diff --git a/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java b/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.javaindex 4222da4a09b..bab9f032be4 100644--- a/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java+++ b/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java@@ -33,13 +33,13 @@ import org.apache.solr.util.SolrPluginUtils;*/public class ExplainAugmenterFactory extends TransformerFactory{- public static enum Style {+ public enum Style {nl,text,html- };+ }- protected Style defaultStyle = null;+ protected Style defaultStyle = Style.text;@Overridepublic void init(NamedList args) {@@ -47,13 +47,9 @@ public class ExplainAugmenterFactory extends TransformerFactoryif( defaultUserArgs != null ) {defaultStyle = getStyle( defaultUserArgs );}- else {- defaultStyle = Style.nl;- }}- public static Style getStyle( String str )- {+ public static Style getStyle( String str ) {try {return Style.valueOf( str );}@@ -66,7 +62,7 @@ public class ExplainAugmenterFactory extends TransformerFactory@Overridepublic DocTransformer create(String field, SolrParams params, SolrQueryRequest req) {String s = params.get("style");- Style style = (s==null)?defaultStyle:getStyle(s);+ Style style = (s == null) ? defaultStyle : getStyle(s);return new ExplainAugmenter( field, style );}@@ -123,6 +119,3 @@ public class ExplainAugmenterFactory extends TransformerFactory}}}---diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig.xmlindex c68e7e04d05..97b31ad375f 100644--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig.xml+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig.xml@@ -560,8 +560,14 @@<str name="df">text</str></lst></initParams>--++ <transformer name="explain1" class="org.apache.solr.response.transform.ExplainAugmenterFactory" />+ <transformer name="explainText" class="org.apache.solr.response.transform.ExplainAugmenterFactory" >+ <str name="args">text</str>+ </transformer>+ <transformer name="explainNL" class="org.apache.solr.response.transform.ExplainAugmenterFactory" >+ <str name="args">nl</str>+ </transformer></config>diff --git a/solr/core/src/test/org/apache/solr/response/transform/TestExplainDocTransformer.java b/solr/core/src/test/org/apache/solr/response/transform/TestExplainDocTransformer.javanew file mode 100644index 00000000000..39c7ca37688--- /dev/null+++ b/solr/core/src/test/org/apache/solr/response/transform/TestExplainDocTransformer.java@@ -0,0 +1,75 @@+/*+ * 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.+ */++package org.apache.solr.response.transform;+++import org.apache.solr.SolrTestCaseJ4;+import org.junit.After;+import org.junit.BeforeClass;+import org.junit.Test;++public class TestExplainDocTransformer extends SolrTestCaseJ4 {++ @BeforeClass+ public static void beforeClass() throws Exception {+ initCore("solrconfig.xml","schema.xml");++ assertU(add(doc("id", "1", "name_s", "john", "title_s", "Director", "dept_s","Engineering",+ "text_t","These guys develop stuff")));+ assertU(add(doc("id", "2", "name_s", "mark", "title_s", "VP", "dept_s","Marketing",+ "text_t","These guys make you look good")));+ assertU(add(doc("id", "3", "name_s", "nancy", "title_s", "MTS", "dept_s","Sales",+ "text_t","These guys sell stuff")));+ assertU(add(doc("id", "4", "name_s", "dave", "title_s", "MTS", "dept_s","Support",+ "text_t","These guys help customers")));+ assertU(add(doc("id", "5", "name_s", "tina", "title_s", "VP", "dept_s","Engineering",+ "text_t","These guys develop stuff")));+ assertU(commit());+ }++ @After+ public void cleanup() throws Exception {+ assertU(delQ("*:*"));+ assertU(commit());+ }++ @Test+ public void testStyle() throws Exception {+ // this doesn't validate the explain response but checks if explain response is returned in expected format++ // when not style is passed then default style should be used+ assertQ(req("q", "*:*", "fl", "id,[explain]"), "//result/doc[1]/str[@name='id'][.='1']",+ "boolean(//result/doc[1]/str[@name='[explain]'])");++ // doc transformer defined in solrconfig without style+ assertQ(req("q", "*:*", "fl", "id,[explain1]"), "//result/doc[1]/str[@name='id'][.='1']",+ "boolean(//result/doc[1]/str[@name='[explain1]'])");++ // doc transformer defined in solrconfig with style=nl+ assertQ(req("q", "*:*", "fl", "id,[explainNL]"), "//result/doc[1]/str[@name='id'][.='1']",+ "boolean(//result/doc[1]/lst[@name='[explainNL]'])");++ // doc transformer defined in solrconfig with style=nl+ assertQ(req("q", "*:*", "fl", "id,[explainText]"), "//result/doc[1]/str[@name='id'][.='1']",+ "boolean(//result/doc[1]/str[@name='[explainText]'])");++ // passing style as parameter at runtime+ assertQ(req("q", "*:*", "fl", "id,[explainText style=nl]"), "//result/doc[1]/str[@name='id'][.='1']",+ "boolean(//result/doc[1]/lst[@name='[explainText]'])");+ }+}