[
https://issues.apache.org/jira/browse/SOLR-12402?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16491346#comment-16491346
]
Christine Poerschke commented on SOLR-12402:
--------------------------------------------
Here's a outline example of what a custom class requiring access to a
{{SolrResourceLoader}} might look like. There are some similarities to the
https://github.com/deeplearning4j/deeplearning4j/blob/deeplearning4j-1.0.0-beta/deeplearning4j-modelexport-solr/src/main/java/org/deeplearning4j/nn/modelexport/solr/ltr/model/ScoringModel.java
class.
Illustration:
{code}
package org.deeplearning4j.nn.modelexport.solr.handler;
...
import org.deeplearning4j.nn.api.Model;
...
/**
* ...
* Illustrative configuration snippet:
* <pre>
<lst name="streamFunctions">
<str
name="emailModel">org.deeplearning4j.nn.modelexport.solr.handler.ModelTupleStream</str>
</lst>
</pre>
* ...
* Illustrative expression snippet:
* <pre>
emailModel(search(myCollection,
q="*:*",
fl="id,fieldX,fieldY,fieldZ",
sort="id asc",
qt="/export"),
serializedModelFileName="mySerializedModel",
inputFields="fieldX,fieldY,fieldZ",
outputField="modelScoreField")
</pre>
* <p>
* Apache Solr Reference Guide:
* <ul>
* <li> <a
href="https://lucene.apache.org/solr/guide/7_3/streaming-expressions.html">Streaming
Expressions</a>
* </ul>
*/
public static class ModelTupleStream extends TupleStream implements Expressible
{
final private TupleStream tupleStream;
final private String serializedModelFileName;
final private Model model;
final private String[] inputFields;
final private String[] outputField;
public ModelTupleStream(StreamExpression streamExpression, StreamFactory
streamFactory) throws IOException {
...
this.tupleStream = streamFactory.constructStream(...);
this.serializedModelFileName = ...
streamFactory.getNamedOperand(streamExpression, "serializedModelFileName") ...
if (!(streamFactory instanceof SolrDefaultStreamFactory)) {
throw new IOException(...);
}
final SolrResourceLoader solrResourceLoader =
((SolrDefaultStreamFactory)streamFactory).getSolrResourceLoader();
final InputStream inputStream =
solrResourceLoader.openResource(serializedModelFileName);
this.model = ModelGuesser.loadModelGuess(inputStream);
}
@Override
public Tuple read() throws IOException;
{
Tuple tuple = tupleStream.read();
if (!tuple.EOF) {
for ... inputFields ...
... tuple.getDouble(inputFields[ii]) ...
outputValue = model(inputValues);
tuple.put(this.outputField, outputValue);
}
return tuple;
}
...
}
{code}
> factor out a SolrDefaultStreamFactory class
> -------------------------------------------
>
> Key: SOLR-12402
> URL: https://issues.apache.org/jira/browse/SOLR-12402
> Project: Solr
> Issue Type: Task
> Components: streaming expressions
> Reporter: Christine Poerschke
> Assignee: Christine Poerschke
> Priority: Minor
> Attachments: SOLR-12402.patch
>
>
> Two motivations behind the proposed factoring out:
> * discoverability of solr/solrj Lang vs. solr/core Lucene/Solr functions
> * support for custom classes that require access to a SolrResourceLoader
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]