timatbw commented on code in PR #2742:
URL: https://github.com/apache/solr/pull/2742#discussion_r1808365601
##########
solr/core/src/java/org/apache/solr/search/facet/FacetParser.java:
##########
@@ -138,21 +139,30 @@ public Object parseFacetOrStat(String key, Object o)
throws SyntaxError {
return parseFacetOrStat(key, type, args);
}
+ public interface ParseHandler {
+ Object doParse(FacetParser<?> parent, String key, Object args) throws
SyntaxError;
+ }
+
+ private static final Map<String, ParseHandler> REGISTERED_TYPES = new
ConcurrentHashMap<>();
+
+ static {
+ ParseHandler fieldParser = (p, k, a) -> new FacetFieldParser(p,
k).parse(a);
+ REGISTERED_TYPES.put("field", fieldParser);
+ REGISTERED_TYPES.put("terms", fieldParser);
+ REGISTERED_TYPES.put("query", (p, k, a) -> new FacetQueryParser(p,
k).parse(a));
+ REGISTERED_TYPES.put("range", (p, k, a) -> new FacetRangeParser(p,
k).parse(a));
+ REGISTERED_TYPES.put("heatmap", (p, k, a) -> new FacetHeatmap.Parser(p,
k).parse(a));
+ REGISTERED_TYPES.put("func", (p, k, a) -> p.parseStat(k, a));
+ }
+
+ public static void registerParseHandler(String type, ParseHandler
parseHandler) {
Review Comment:
Yeah it's perhaps not the best way of hooking things up, especially as the
whole process is already kicked off from solrconfig.xml where you declare a
valueSourceParser. I was relying on the point at which that custom parser
object is instantiated to run a static initialiser to also register it for json
parsing too. But maybe it's safer to invert that and have the Solr code
register the custom parser if it implements json parsing. I'll have another
look and think about the alternatives.
My main reason for suggesting custom code uses a static block to register is
when you have many hundreds of SolrCores in your CoreContainer and each one
would be instantiated and call the register method, when really you might only
need it done once. But now thinking if you run a mixed workload with different
solrconfig and they're not homogenous, you don't want static registering maybe
(each SolrCore is distinct)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]