mirror of https://github.com/apache/lucene.git
SOLR-13780: fix ClassCastException in NestableJsonFacet
* handle both int and long values for count. In case of single-shard or standalone, count is int whereas in multishard count would be long
This commit is contained in:
parent
e66741aecf
commit
c22379253c
|
@ -222,6 +222,8 @@ Bug Fixes
|
||||||
|
|
||||||
* SOLR-13238: BlobHandler generates non-padded md5 (Jeff Walraven via janhoy)
|
* SOLR-13238: BlobHandler generates non-padded md5 (Jeff Walraven via janhoy)
|
||||||
|
|
||||||
|
* SOLR-13780: Fix ClassCastException in NestableJsonFacet (Tiago Martinho de Barros, Munendra S N)
|
||||||
|
|
||||||
Other Changes
|
Other Changes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class NestableJsonFacet {
|
||||||
if (getKeysToSkip().contains(key)) {
|
if (getKeysToSkip().contains(key)) {
|
||||||
continue;
|
continue;
|
||||||
} else if ("count".equals(key)) {
|
} else if ("count".equals(key)) {
|
||||||
domainCount = (int) entry.getValue();
|
domainCount = ((Number) entry.getValue()).longValue();
|
||||||
} else if(entry.getValue() instanceof Number) { // Stat/agg facet value
|
} else if(entry.getValue() instanceof Number) { // Stat/agg facet value
|
||||||
statFacetsByName.put(key, (Number)entry.getValue());
|
statFacetsByName.put(key, (Number)entry.getValue());
|
||||||
} else if(entry.getValue() instanceof NamedList) { // Either heatmap/query/range/terms facet
|
} else if(entry.getValue() instanceof NamedList) { // Either heatmap/query/range/terms facet
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* 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.client.solrj.response;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
import org.apache.solr.client.solrj.response.json.NestableJsonFacet;
|
||||||
|
import org.apache.solr.common.util.NamedList;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class NestableJsonFacetTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParsing() {
|
||||||
|
NamedList<Object> list = new NamedList<>();
|
||||||
|
list.add("count", 12);
|
||||||
|
NamedList<Object> buckets = new NamedList<Object>() {{
|
||||||
|
add("val", "Nike");
|
||||||
|
}};
|
||||||
|
NamedList<Object> vals = new NamedList<Object>() {{
|
||||||
|
add("numBuckets", 10);
|
||||||
|
add("allBuckets", new NamedList<Object>(){{
|
||||||
|
add("count", 12);
|
||||||
|
}});
|
||||||
|
add("before", new NamedList<Object>(){{
|
||||||
|
add("count", 1);
|
||||||
|
}});
|
||||||
|
add("after", new NamedList<Object>(){{
|
||||||
|
add("count", 2);
|
||||||
|
}});
|
||||||
|
add("between", new NamedList<Object>(){{
|
||||||
|
add("count", 9);
|
||||||
|
}});
|
||||||
|
}};
|
||||||
|
vals.add("buckets", Collections.singletonList(buckets));
|
||||||
|
list.add("test", vals);
|
||||||
|
NestableJsonFacet facet = new NestableJsonFacet(list);
|
||||||
|
|
||||||
|
assertEquals(12L, facet.getCount());
|
||||||
|
assertEquals(9L, facet.getBucketBasedFacets("test").getBetween());
|
||||||
|
list.clear();
|
||||||
|
|
||||||
|
list.add("count", 12L);
|
||||||
|
buckets = new NamedList<Object>() {{
|
||||||
|
add("val", "Nike");
|
||||||
|
}};
|
||||||
|
vals = new NamedList<Object>() {{
|
||||||
|
add("numBuckets", 10L);
|
||||||
|
add("allBuckets", new NamedList<Object>(){{
|
||||||
|
add("count", 12L);
|
||||||
|
}});
|
||||||
|
add("before", new NamedList<Object>(){{
|
||||||
|
add("count", 1L);
|
||||||
|
}});
|
||||||
|
add("after", new NamedList<Object>(){{
|
||||||
|
add("count", 2L);
|
||||||
|
}});
|
||||||
|
add("between", new NamedList<Object>(){{
|
||||||
|
add("count", 9L);
|
||||||
|
}});
|
||||||
|
}};
|
||||||
|
vals.add("buckets", Collections.singletonList(buckets));
|
||||||
|
list.add("test", vals);
|
||||||
|
facet = new NestableJsonFacet(list);
|
||||||
|
assertEquals(12L, facet.getCount());
|
||||||
|
assertEquals(2L, facet.getBucketBasedFacets("test").getAfter());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue