Apache Lucene open-source search software
SOLR-10526: fix facet.heatmap facet exclusion when distributed/sharded
David Smiley8a9993798054
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 243822922e2..62df77679e4 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -253,6 +253,8 @@ Bug Fixes* SOLR-10480: Full pagination in JSON Facet API using offset does not work. (yonik)+* SOLR-10526: facet.heatmap didn't honor facet exclusions ('ex') for distributed search. (David Smiley)+Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/handler/component/SpatialHeatmapFacets.java b/solr/core/src/java/org/apache/solr/handler/component/SpatialHeatmapFacets.javaindex bf1e2b08616..656372a4d72 100644--- a/solr/core/src/java/org/apache/solr/handler/component/SpatialHeatmapFacets.java+++ b/solr/core/src/java/org/apache/solr/handler/component/SpatialHeatmapFacets.java@@ -38,10 +38,9 @@ import org.apache.lucene.spatial.query.SpatialArgs;import org.apache.lucene.spatial.query.SpatialOperation;import org.apache.lucene.util.Bits;import org.apache.lucene.util.FixedBitSet;-import org.apache.solr.client.solrj.util.ClientUtils;import org.apache.solr.common.SolrException;-import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.FacetParams;+import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.SimpleOrderedMap;@@ -291,38 +290,20 @@ public class SpatialHeatmapFacets {* {@link org.apache.solr.handler.component.SearchComponent#modifyRequest(ResponseBuilder, SearchComponent, ShardRequest)}. */public static void distribModifyRequest(ShardRequest sreq, LinkedHashMap<String, HeatmapFacet> heatmapFacets) {// Set the format to PNG because it's compressed and it's the only format we have code to read at the moment.- // Changing a param is sadly tricky because field-specific params can show up as local-params (highest precedence)- // or as f.key.facet.heatmap.whatever. Ugh. So we re-write the facet.heatmap list with the local-params- // moved out to the "f.key." prefix, but we need to keep the key local-param because that's the only way to- // set an output key. This approach means we only need to know about the parameter we're changing, not of- // all possible heatmap params.+ // We re-write the facet.heatmap list with PNG format in local-params where it has highest precedence.//Remove existing heatmap field param vals; we will rewritesreq.params.remove(FacetParams.FACET_HEATMAP);- for (Map.Entry<String, HeatmapFacet> entry : heatmapFacets.entrySet()) {- final String key = entry.getKey();- final HeatmapFacet facet = entry.getValue();+ for (HeatmapFacet facet : heatmapFacets.values()) {//add heatmap field param- if (!key.equals(facet.facetOn)) {- sreq.params.add(FacetParams.FACET_HEATMAP,- "{!" + CommonParams.OUTPUT_KEY + "=" + ClientUtils.encodeLocalParamVal(key) + "}" + facet.facetOn);- } else {- sreq.params.add(FacetParams.FACET_HEATMAP, facet.facetOn);- }- // Turn local-params into top-level f.key.param=value style params+ ModifiableSolrParams newLocalParams = new ModifiableSolrParams();if (facet.localParams != null) {- final Iterator<String> localNameIter = facet.localParams.getParameterNamesIterator();- while (localNameIter.hasNext()) {- String pname = localNameIter.next();- if (!pname.startsWith(FacetParams.FACET_HEATMAP)) {- continue; // could be 'key', or 'v' even- }- String pval = facet.localParams.get(pname);- sreq.params.set("f." + key + "." + pname, pval);- }+ newLocalParams.add(facet.localParams);}// Set format to PNG; it's the only one we parse- sreq.params.set("f." + key + "." + FacetParams.FACET_HEATMAP_FORMAT, FORMAT_PNG);+ newLocalParams.set(FacetParams.FACET_HEATMAP_FORMAT, FORMAT_PNG);+ sreq.params.add(FacetParams.FACET_HEATMAP,+ newLocalParams.toLocalParamsString() + facet.facetOn);}}diff --git a/solr/core/src/test/org/apache/solr/handler/component/SpatialHeatmapFacetsTest.java b/solr/core/src/test/org/apache/solr/handler/component/SpatialHeatmapFacetsTest.javaindex 78dd919514f..8d66b07e72e 100644--- a/solr/core/src/test/org/apache/solr/handler/component/SpatialHeatmapFacetsTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/SpatialHeatmapFacetsTest.java@@ -119,6 +119,28 @@ public class SpatialHeatmapFacetsTest extends BaseDistributedSearchTestCase {counts);+ // now this time we add a filter query and exclude it+ QueryResponse response = query(params(baseParams,+ "fq", "{!tag=excludeme}id:0", // filter to only be id:0+ FacetParams.FACET_HEATMAP, "{!ex=excludeme}" + FIELD, // exclude the filter+ FacetParams.FACET_HEATMAP_GEOM, "[\"50 20\" TO \"180 90\"]",+ FacetParams.FACET_HEATMAP_LEVEL, "4"));+ assertEquals(1, response.getResults().getNumFound());// because of our 'fq'+ hmObj = getHmObj(response);+ counts = (List<List<Integer>>) hmObj.get("counts_ints2D");+ assertEquals(+ Arrays.asList( // same counts as before+ Arrays.asList(0, 0, 2, 1, 0, 0),+ Arrays.asList(0, 0, 1, 1, 0, 0),+ Arrays.asList(0, 1, 1, 1, 0, 0),+ Arrays.asList(0, 0, 1, 1, 0, 0),+ Arrays.asList(0, 0, 1, 1, 0, 0),+ null,+ null+ ),+ counts+ );+// test using a circle input shapehmObj = getHmObj(query(params(baseParams,FacetParams.FACET_HEATMAP_GEOM, "BUFFER(POINT(110 40), 7)",