From 4a1ee046c37615b3927737618c9a4c937bd6ede9 Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Tue, 31 Jul 2018 18:47:53 +0100 Subject: [PATCH] SOLR-12402: Factor out SolrDefaultStreamFactory class. --- solr/CHANGES.txt | 2 + .../handler/SolrDefaultStreamFactory.java | 53 +++++++++++++++++++ .../apache/solr/handler/StreamHandler.java | 11 +--- 3 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 solr/core/src/java/org/apache/solr/handler/SolrDefaultStreamFactory.java diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 2d8db8c0f2c..37dd5a7065b 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -129,6 +129,8 @@ New Features future cluster operations whether they are invoked manually via the Collection API or by the Autoscaling framework. (noble, shalin) +* SOLR-12402: Factor out SolrDefaultStreamFactory class. (Christine Poerschke) + Bug Fixes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/SolrDefaultStreamFactory.java b/solr/core/src/java/org/apache/solr/handler/SolrDefaultStreamFactory.java new file mode 100644 index 00000000000..0b375f475a6 --- /dev/null +++ b/solr/core/src/java/org/apache/solr/handler/SolrDefaultStreamFactory.java @@ -0,0 +1,53 @@ +/* + * 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.handler; + +import org.apache.solr.client.solrj.io.Lang; +import org.apache.solr.client.solrj.io.stream.expr.DefaultStreamFactory; +import org.apache.solr.core.SolrResourceLoader; + +/** + * A default collection of mappings, used to convert strings into stream expressions. + * Same as {@link DefaultStreamFactory} plus functions that rely directly on either + * Lucene or Solr capabilities that are not part of {@link Lang}. + * + * @since 7.5 + */ +public class SolrDefaultStreamFactory extends DefaultStreamFactory { + + private SolrResourceLoader solrResourceLoader; + + public SolrDefaultStreamFactory() { + super(); + this.withFunctionName("analyze", AnalyzeEvaluator.class); + this.withFunctionName("classify", ClassifyStream.class); + } + + public SolrDefaultStreamFactory withSolrResourceLoader(SolrResourceLoader solrResourceLoader) { + this.solrResourceLoader = solrResourceLoader; + return this; + } + + public void setSolrResourceLoader(SolrResourceLoader solrResourceLoader) { + this.solrResourceLoader = solrResourceLoader; + } + + public SolrResourceLoader getSolrResourceLoader() { + return solrResourceLoader; + } + +} diff --git a/solr/core/src/java/org/apache/solr/handler/StreamHandler.java b/solr/core/src/java/org/apache/solr/handler/StreamHandler.java index 4e43e1ceb06..e6ebc51edaa 100644 --- a/solr/core/src/java/org/apache/solr/handler/StreamHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/StreamHandler.java @@ -31,7 +31,6 @@ import org.apache.solr.client.solrj.io.SolrClientCache; import org.apache.solr.client.solrj.io.Tuple; import org.apache.solr.client.solrj.io.comp.StreamComparator; import org.apache.solr.client.solrj.io.stream.*; -import org.apache.solr.client.solrj.io.stream.expr.DefaultStreamFactory; import org.apache.solr.client.solrj.io.stream.expr.Explanation; import org.apache.solr.client.solrj.io.stream.expr.Explanation.ExpressionType; import org.apache.solr.client.solrj.io.stream.expr.Expressible; @@ -65,7 +64,7 @@ public class StreamHandler extends RequestHandlerBase implements SolrCoreAware, static SolrClientCache clientCache = new SolrClientCache(); static ModelCache modelCache = null; - private StreamFactory streamFactory = new DefaultStreamFactory(); + private SolrDefaultStreamFactory streamFactory = new SolrDefaultStreamFactory(); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private String coreName; private Map daemons = Collections.synchronizedMap(new HashMap()); @@ -105,13 +104,7 @@ public class StreamHandler extends RequestHandlerBase implements SolrCoreAware, defaultZkhost, clientCache); } - - /* - * Add the core functions. These are functions that rely directly on either Lucene or Solr - * capabilities that are not part of Lang. - */ - streamFactory.withFunctionName("analyze", AnalyzeEvaluator.class); - streamFactory.withFunctionName("classify", ClassifyStream.class); + streamFactory.withSolrResourceLoader(core.getResourceLoader()); // This pulls all the overrides and additions from the config List pluginInfos = core.getSolrConfig().getPluginInfos(Expressible.class.getName());