mirror of https://github.com/apache/lucene.git
SOLR-13679:Fix default style of [explain] registered in solrconfig.xml
This commit is contained in:
parent
751e64651c
commit
84a62a5d87
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
||||
@Override
|
||||
public void init(NamedList args) {
|
||||
|
@ -47,13 +47,9 @@ public class ExplainAugmenterFactory extends TransformerFactory
|
|||
if( 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
|
|||
@Override
|
||||
public 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
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -561,7 +561,13 @@
|
|||
</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>
|
||||
|
||||
|
|
|
@ -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]'])");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue