Class DocTransformer
- java.lang.Object
-
- org.apache.solr.response.transform.DocTransformer
-
- Direct Known Subclasses:
BaseEditorialTransformer
,DocTransformer.NoopFieldTransformer
,DocTransformers
,RenameFieldTransformer
,ScoreAugmenter
,ValueSourceAugmenter
public abstract class DocTransformer extends Object
A DocTransformer can add, remove or alter a Document before it is written out to the Response. For instance, there are implementations that can put explanations inline with a document, add constant values and mark items as being artificially boosted (seeQueryElevationComponent
)New instance for each request
- See Also:
TransformerFactory
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DocTransformer.NoopFieldTransformer
Trivial Impl that ensure that the specified field is requested as an "extra" field, but then does nothing during the transformation phase.
-
Field Summary
Fields Modifier and Type Field Description protected ResultContext
context
-
Constructor Summary
Constructors Constructor Description DocTransformer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String[]
getExtraRequestFields()
When a transformer needs access to fields that are not automatically derived from the input fields names, this option lets us explicitly say the field names that we hope will be in the SolrDocument.abstract String
getName()
boolean
needsSolrIndexSearcher()
Indicates if this transformer requires access to the underlying index to perform it's functions.void
setContext(ResultContext context)
This is called beforetransform(org.apache.solr.common.SolrDocument, int, float)
to provide context for any subsequent transformations.String
toString()
abstract void
transform(SolrDocument doc, int docid)
This is where implementations do the actual work.void
transform(SolrDocument doc, int docid, float score)
This is where implementations do the actual work.
-
-
-
Field Detail
-
context
protected ResultContext context
-
-
Method Detail
-
getName
public abstract String getName()
- Returns:
- The name of the transformer
-
setContext
public void setContext(ResultContext context)
This is called beforetransform(org.apache.solr.common.SolrDocument, int, float)
to provide context for any subsequent transformations.- Parameters:
context
- TheResultContext
stores information about how the documents were produced.- See Also:
needsSolrIndexSearcher()
-
needsSolrIndexSearcher
public boolean needsSolrIndexSearcher()
Indicates if this transformer requires access to the underlying index to perform it's functions. In some situations (notably RealTimeGet) this method may be called beforesetContext(org.apache.solr.response.ResultContext)
to determine if the transformer must be given a "full" ResultContext and accurate docIds that can be looked up usingResultContext.getSearcher()
, or if optimizations can be taken advantage of such thatResultContext.getSearcher()
may return null, and docIds passed totransform(org.apache.solr.common.SolrDocument, int, float)
may be negative. The default implementation always returnsfalse
.
-
transform
public void transform(SolrDocument doc, int docid, float score) throws IOException
This is where implementations do the actual work. If implementations require a valid docId and index access, theneedsSolrIndexSearcher()
method must return true Default implementation callstransform(SolrDocument, int)
.- Parameters:
doc
- The document to alterdocid
- The Lucene internal doc id, or -1 in cases where thedoc
did not come from the indexscore
- the score for this document- Throws:
IOException
- If there is a low-level I/O error.- See Also:
needsSolrIndexSearcher()
-
transform
public abstract void transform(SolrDocument doc, int docid) throws IOException
This is where implementations do the actual work. If implementations require a valid docId and index access, theneedsSolrIndexSearcher()
method must return true- Parameters:
doc
- The document to alterdocid
- The Lucene internal doc id, or -1 in cases where thedoc
did not come from the index- Throws:
IOException
- If there is a low-level I/O error.- See Also:
needsSolrIndexSearcher()
-
getExtraRequestFields
public String[] getExtraRequestFields()
When a transformer needs access to fields that are not automatically derived from the input fields names, this option lets us explicitly say the field names that we hope will be in the SolrDocument. These fields will be requested from theSolrIndexSearcher
but may or may not be returned in the finalQueryResponseWriter
- Returns:
- a list of extra lucene fields
-
-