org.apache.solr.response.transform

## Class DocTransformer

- java.lang.Object
- - org.apache.solr.response.transform.DocTransformer

- Direct Known Subclasses:
    BaseEditorialTransformer, 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 (see `QueryElevationComponent`)

  New instance for each request

  See Also:
    `TransformerFactory`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ResultContext` | `context`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DocTransformer()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and 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 before `transform(org.apache.solr.common.SolrDocument, int, float)` to provide context for any subsequent transformations.
    `String` | `toString()`
    `abstract void` | `transform(SolrDocument doc, int docid, float score)` This is where implementations do the actual work.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### context

          protected ResultContext context

  - ### Constructor Detail

    - #### DocTransformer

          public DocTransformer()

  - ### Method Detail

    - #### getName

          public abstract String getName()

      Returns:
        The name of the transformer

    - #### setContext

          public void setContext(ResultContext context)

      This is called before `transform(org.apache.solr.common.SolrDocument, int, float)` to provide context for any subsequent transformations.
      Parameters:
        `context` - The `ResultContext` 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 before `setContext(org.apache.solr.response.ResultContext)` to determine if the transformer must be given a "full" ResultContext and accurate docIds that can be looked up using `ResultContext.getSearcher()`, or if optimizations can be taken advantage of such that `ResultContext.getSearcher()` may return null, and docIds passed to `transform(org.apache.solr.common.SolrDocument, int, float)` may be negative. The default implementation always returns `false`.
      See Also:
        `ResultContext.getSearcher()`, `transform(org.apache.solr.common.SolrDocument, int, float)`

    - #### transform

          public abstract 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, the `needsSolrIndexSearcher()` method must return true
      Parameters:
        `doc` - The document to alter
        `docid` - The Lucene internal doc id, or -1 in cases where the `doc` did not come from the index
        `score` - the score for this document
      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 the `SolrIndexSearcher` but may or may not be returned in the final `QueryResponseWriter`
      Returns:
        a list of extra lucene fields

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.