From 86a794133b38ae80f35eb38a724b15c4964eb1a5 Mon Sep 17 00:00:00 2001 From: Mikhail Khludnev Date: Mon, 21 Oct 2024 09:33:45 +0300 Subject: [PATCH] SOLR-17477: adding changes and one more demo test --- solr/CHANGES.txt | 2 + .../function/CustomParseHandlerTest.java | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 solr/core/src/test/org/apache/solr/search/function/CustomParseHandlerTest.java diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 80ed44d47ce..1d491ce925c 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -112,6 +112,8 @@ Improvements * SOLR-17397: SkipExistingDocumentsProcessor now functions correctly with child documents. (Tim Owens via Eric Pugh) * SOLR-17180: Deprecate snapshotscli.sh in favour of bin/solr snapshot sub commands. Now able to manage Snapshots from the CLI. HDFS module specific snapshot script now ships as part of that module in the modules/hdfs/bin directory. (Eric Pugh) +* SOLR-17477: Let to extend FacetModule aka JSON DSL Facet (Tim Owen, Christine Poerschke via Mikhail Khludnev) + Optimizations --------------------- * SOLR-14985: Solrj CloudSolrClient with Solr URLs had serious performance regressions (since the diff --git a/solr/core/src/test/org/apache/solr/search/function/CustomParseHandlerTest.java b/solr/core/src/test/org/apache/solr/search/function/CustomParseHandlerTest.java new file mode 100644 index 00000000000..0c906ff9484 --- /dev/null +++ b/solr/core/src/test/org/apache/solr/search/function/CustomParseHandlerTest.java @@ -0,0 +1,47 @@ +package org.apache.solr.search.function; + +import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.handler.component.ResponseBuilder; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.search.SyntaxError; +import org.apache.solr.search.facet.FacetField; +import org.apache.solr.search.facet.FacetParser; +import org.apache.solr.search.facet.FacetRequest; +import org.junit.BeforeClass; + +import java.util.Collections; +import java.util.Map; + + +public class CustomParseHandlerTest extends SolrTestCaseJ4 { + + public static final FacetField FACET_FIELD_STUB = new FacetField(); + + static class CustomParseHandler implements FacetParser.ParseHandler { + @Override + public Object doParse(FacetParser parent, String key, Object args) { + assertEquals("arg", args); + return FACET_FIELD_STUB; + } + } + + @BeforeClass + public static void beforeClass() throws Exception { + initCore("solrconfig.xml", "schema.xml"); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + FacetParser.registerParseHandler("custom", new CustomParseHandler()); + } + + public void testCustomParseHandler() { + SolrQueryRequest req = req(); + ResponseBuilder rsp = new ResponseBuilder(req, new SolrQueryResponse(), Collections.emptyList()); + + FacetRequest facetRequest = FacetRequest.parse(rsp.req, Map.of("bogus",Map.of("custom","arg"))); + assertEquals(FACET_FIELD_STUB, facetRequest.getSubFacets().get("bogus")); + } +}